Announcement Announcement Module
Collapse
No announcement yet.
JMS and Spring integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMS and Spring integration

    I have a requirement where I need Spring Integration to be a listener for the JMS message. After receiving the message, it needs to process and it will act as a JMS producer.

    Can you please provide some sample code ?

    Thanks

  • #2
    See the basic JMS sample here... https://github.com/SpringSource/spri...ration-samples

    The inboundChannelAdapter.xml shows an inbound adapter sending the message to stdout.
    The outboundChannelAdapter.xml shows messages from stdin being sent to JMS.

    Just join the two together, replacing stdout/stdin with your <service-activator/> to process the request.

    If you use ackknowledge="transacted" on the inbound adapter, both JMS operations will occur in the same transaction.

    Comment


    • #3
      This is probably the best starting point: https://github.com/SpringSource/spri...ster/basic/jms

      There are also several excerpts in the reference manual.

      Hope that helps.
      -Mark

      Comment


      • #4
        Thanks for the reply.

        I am able to configure my spring integration to listen to ActiveMQ JMS message using "<int-jms:message-driven-channel-adapter" and then forward the message to an service activator where it does some manipulation.

        Now my question is, from my service activator, I want to send the response as JMS, which I have am able to do using jmstemplate. Is this the right approach for sending my JMS response from spring integration?

        Comment


        • #5
          It sounds like you might want to consider using jms:inbound-gateway instead. That supports bi-directional request/reply messaging whereas channel-adapters are all uni-directional.

          The jms:inbound-gateway will actually handle a JMSReplyTo property automatically.

          Hope that helps.
          -Mark

          Comment


          • #6
            Can you please provide "jms:inbound-gateway" configuration where I need to mention the listening queue name and the reply queue name or direct me to any sample code for the same?

            Also I am assuming that in my service activator, I need not to do anything. the message that is returned will be automatically be send to the reply queue using this "jms:inbound-gateway". Hope this is correct?

            Comment


            • #7
              In the samples we linked to above, there is a GatewayDemo. That should provide all the info you need.

              Your assumption about the service-activator is correct - just return a value.

              Comment


              • #8
                Thank for the reply. My below question may be very silly but wanted to clarify. I want to send JMS message as java object from my spring integration application. In my other application, I wanted to receive the java object from JMS message. I have implemented serialization in my java object and package as a jar. Now in two applications, I share this jar so that the object can be used from the JMS message.
                Is this approach correct for sending object from JMS message?

                Comment


                • #9
                  Not a silly question. You can use serialized Java instances. The default Spring MessageConverter will recognize a JMS ObjectMessage and deserialize its body - likewise on the other side (serialize to create an outbound ObjectMessage). That said, relying on Java serialization does result in tight coupling. You should be wary of that unless you have a situation where both sides will *always* be updated together. Personally, I recommend avoiding Java serialization in favor of more loosely coupled options like JSON or alternative serialization protocols (Avro, Thrift, protobuf, ...).

                  Comment


                  • #10
                    As you have suggested to use "jms:inbound-gateway" for request and reply JMS message. I can mentioned the request queue name inside "request-destination-name". However, I do not find a way to mentioned the reply queue name. Can you please guide me?

                    Comment


                    • #11
                      You can use the 'default-reply-queue-name' attribute. The reason it is prefixed with "default" is that IF a received Message contains an actual JMSReplyTo property, that would take precedence. Otherwise, the default as configured would be used.

                      Hope that helps.
                      -Mark

                      Comment


                      • #12
                        Thanks you all for your help. It worked perfectly for me.

                        Comment


                        • #13
                          Hi,

                          As I have informed you before, the above configuration is working fine.
                          I have a requirement where depending on the result from the service activator, I need to forward to different queue. As I am using "int-jms:inbound-gateway" where I mentioned my "request queue name" and "default reply queue name". But in my scenario, I cannot mentioned my "default reply queue name" as it will be dynamic.

                          Can you please help in this?

                          Comment


                          • #14
                            With a gateway, you only have the choice of sending to the JMSReplyTo supplied by the client or a default reply queue.

                            Sounds like you need to use a <jms:message-driven-channel-adapter/> and send the result to a <jms:outbound-channel-adapter/> with a destination-expression that will resolve to the queue name.

                            Comment


                            • #15
                              I dont find "destination-expression" in <jms:outbound-channel-adapter/> . I am using spring integration 2.1 version.

                              Comment

                              Working...
                              X