Results 1 to 3 of 3

Thread: Map<String,String> in message header not reaching JMS consumer using channel adapter

  1. #1
    Join Date
    Jan 2012
    Posts
    9

    Default Map<String,String> in message header not reaching JMS consumer using channel adapter

    Hi,
    As part of our application we create a message with some fixed String Message Header values. However some custom values are saved into a Map with value object types as Strings.
    When the JMS consumer receives the message from the <jms-outbound-channel-adapter> this map with values in the header are missing (probably for obvious reasons). What is the best way to push these across.

    Here is some sample code to demonstrate the need.

    Code:
    Map<String,String> customHeaders = new Hashmap<String,String>();
    String headerFieldName = "custom1";
    String customHeaderToken = "customValue";
    customHeaders.put(headerFieldName, customHeaderToken);
    The message is built using:
    Code:
    Message<String> message = MessageBuilder.withPayload(payload)
    								  .setHeader("customerIdentifier",customerIdentifier)
    								  .setHeader("cmdType", commandType)
    								  .setHeader("cmdVersion", version)
    								  .setHeader("cmdVendor", vendorId)
    								  .setHeader("cmdVendorChannel", vendorChannelId)
    								  .setHeader("cmdSubVendor", subVendorId)
    								  .setHeader("cmdCustomHeaders",customHeaders)
    								  .build();
    To send, we use a jms-outbound-channel-adapter:

    Code:
    <int-jms:outbound-channel-adapter id = "senderAdapter" destination-expression = "headers.cmdVendorChannel"
    		                                  channel = "vendorProcessingChannel" extract-payload = "true" >
        <poller fixed-rate = "30000"></poller>
    </int-jms:outbound-channel-adapter>
    All other header properties reach the consumer via TextMessage, however the cmdCustomHeaders DOES NOT get across.

    Any pointers on how to get this Map of Strings across with <jms-outbound-channel-adapter> ? Would I have to override HeaderMappingMessageConverter or some such ?

    Thanks
    Vinay

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,843

    Default

    Only headers that are supported types for JMS properties will be mapped across. You can see those in our DefaultJmsHeaderMapper:
    Code:
    private static List<Class<?>> SUPPORTED_PROPERTY_TYPES = Arrays.asList(new Class<?>[] {
            Boolean.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class, String.class });
    So, maybe you can flatten your map in some way (e.g. JSON?) so it can be passed as a String?

    Also, you should be seeing a message in the logs that the header is being skipped. Can you please verify that?

    Hope that helps.
    -Mark

  3. #3
    Join Date
    Jan 2012
    Posts
    9

    Default

    I don't see any message in the logs which says that the header is being skipped. Here are some snippets from the log for you to view.

    Code:
    2012-02-01 12:56:41,249 DEBUG [org.springframework.integration.endpoint.PollingConsumer] - <Poll resulted in Message: [Payload=itemcode1#20#itemcode2#30][Headers={correlationId=17013872-9c7f-4fbe-9a02-79dd6cf2fe44, expirationDate=1328081779207, qrevCmdType=qsho, sequenceSize=2, qrevVendor=1, sequenceNumber=1, qrevVersion=1, id=98bdfd2e-37dc-4e72-9a97-c84ce9e20c96, timestamp=1328081179305, qrevVendorChannel=qrevVC1, qrevCustomHeaders={custom1=aa, custom2=bb}, customerIdentifier=B1, qrevSubVendor=1}]>
    2012-02-01 12:56:41,250 DEBUG [org.springframework.integration.jms.JmsSendingMessageHandler] - <org.springframework.integration.jms.JmsSendingMessageHandler#0 received message: [Payload=itemcode1#20#itemcode2#30][Headers={correlationId=17013872-9c7f-4fbe-9a02-79dd6cf2fe44, expirationDate=1328081779207, qrevCmdType=qsho, sequenceSize=2, qrevVendor=1, sequenceNumber=1, qrevVersion=1, id=98bdfd2e-37dc-4e72-9a97-c84ce9e20c96, timestamp=1328081179305, qrevVendorChannel=qrevVC1, qrevCustomHeaders={custom1=aa, custom2=bb}, customerIdentifier=B1, qrevSubVendor=1}]>
    We can see the entry "qrevCustomHeaders={custom1=aa, custom2=bb}" which are the custom header Map<String,String> entries just before the send. Here are the next few entries from the log file, in sequence

    Code:
    2012-02-01 12:56:41,253 DEBUG [org.springframework.jms.connection.CachingConnectionFactory] - <Creating cached JMS Session for mode 1: ActiveMQSession {id=ID:libra.local-49368-1328081171066-0:1:8,started=true}>
    2012-02-01 12:56:41,254 DEBUG [org.springframework.integration.jms.DynamicJmsTemplate] - <Executing callback on JMS Session: Cached JMS Session: ActiveMQSession {id=ID:libra.local-49368-1328081171066-0:1:8,started=true}>
    2012-02-01 12:56:41,254 DEBUG [org.springframework.jms.connection.CachingConnectionFactory] - <Creating cached JMS MessageProducer for destination [queue://qrevVC1]: ActiveMQMessageProducer { value=ID:libra.local-49368-1328081171066-0:1:8:1 }>
    2012-02-01 12:56:41,255 DEBUG [org.springframework.integration.jms.DynamicJmsTemplate] - <Sending created message: ActiveMQTextMessage {commandId = 0, responseRequired = false, messageId = null, originalDestination = null, originalTransactionId = null, producerId = null, destination = null, transactionId = null, expiration = 0, timestamp = 0, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = false, type = null, priority = 0, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {timestamp=1328081179305, qrevVersion=1, expirationDate=1328081779207, qrevVendorChannel=qrevVC1, qrevCmdType=qsho, sequenceSize=2, customerIdentifier=B1, sequenceNumber=1, qrevVendor=1, qrevSubVendor=1}, readOnlyProperties = false, readOnlyBody = false, droppable = false, text = itemcode1#20#itemcode2#30}>
    Nothing in the logs which say the Map will be skipped in the header. Am I missing something or do I have my config incorrect for the logging. I have set log level to DEBUG

    Regards
    Vinay

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •