Announcement Announcement Module
Collapse
No announcement yet.
Retrieving JMS MapMessage from ActiveMQ with Spring-Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieving JMS MapMessage from ActiveMQ with Spring-Integration

    Good Morning,

    I'm developing comunication between a Server and a Node applications using ActiveMQ and JMS MapMessages. On Server i'm using Spring-Integration to retrieve messages from a Queue. On Node i'm using JMS directly.

    My MapMessage contains some "message properties" that identifies the included content , also contais the message main body using some "body properties". Here is an example:

    Code:
    MapMessage mensaje = sesion.createMapMessage();
    
    // MESSAGE PROPERTIES
    mensaje.setStringProperty("ID_NODO", "1");
    mensaje.setBooleanProperty("BROADCAST", Boolean.FALSE);            
    mensaje.setStringProperty("TYPE", "ReadWriteMessage");
    
    
    // BODY
    mensaje.setString("ID_SIGNAL", "12");
    mensaje.setString("VALUE", "5");
    The Spring-Integration configuration is:
    Code:
    <bean id="activeMQConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL">
            <value>${mq.broker.url}</value>
        </property>
    </bean>
    
    
    <bean id="recieveQueue" class="org.apache.activemq.command.ActiveMQQueue"
          autowire="constructor">
        <constructor-arg value="${MQ_QUEUE_RECIEVE_FROM}" />
    </bean>
    
    
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
            <ref local="activeMQConnectionFactory"/>
        </property>
        <property name="defaultDestination">            
            <ref  local="sendQueue"/>
        </property>
     </bean>
     
    <bean id="myListener" class="es.example.MyListener"/>        
    
    <integration:channel id="asyncJMSInboundChannel" />
    
    <jms:message-driven-channel-adapter 
                channel="asyncJMSInboundChannel" 
                destination="recieveQueue" 
                connection-factory="activeMQConnectionFactory" />
    
    <integration:service-activator 
                input-channel="asyncJMSInboundChannel" 
                ref="myListener" 
                method="receiveAsyncMessageFromMQ"/>
    Node sends a MapMessage to Server correctly, but when Server retrieves the message from ActiveMQ with Spring-Integration, the object retrieved is a HashMap instead a MapMessage. Recieved message only contains the body properties but any other message properties Node's set.

    For example, using the above code values, the HashMap contect would be:

    [ID_SIGNAL],[12]
    [VALUE],[5]

    What has happened with Message properties? How could I retrieve them?

    Thank you very much!

    Best regards,
    Rafa.

  • #2
    By default, the properties are mapped to the SI message headers, with the payload being the converted message (Map).

    See DefaultJmsHeaderMapper.

    How to access the headers, depends on the method signature of receiveAsyncMessageFromMQ.

    If it's
    Code:
    receiveAsyncMessageFromMQ(Map<?, ?> map)
    you'll just get the payload.

    If it's
    Code:
    receiveAsyncMessageFromMQ(@Payload Map<?,?> payload, @Headers Map<?,?> headers)
    you'll get the payload and headers in the two maps.

    If it's
    Code:
    receiveAsyncMessageFromMQ(@Payload Map<?,?> payload, @Header("foo") String foo, ...)
    you'll get the payload and separate headers of interest.

    If it's
    Code:
    receiveAsyncMessageFromMQ(Message<?> message)
    you can get headers and payload properties from the message (this is generally not recommended because it ties you to the framework). The second and third also have framework dependencies (annotations), but it's easier to write unit tests.

    Finally, you can set extract-payload="false" on the message-driven-adapter, in which case the message payload will be the unconverted JMS MapMessage (although the headers will still be mapped, for routing, etc purposes).

    In this case, the parameter would be the JMS Message.

    Comment


    • #3
      Hi Gary!,

      Thank you very much for your help! I'll apply your tips as soon as possible.

      Best regards,
      Rafa.

      Comment

      Working...
      X