Announcement Announcement Module
Collapse
No announcement yet.
Alternative to SimpleMessagingGateway ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Alternative to SimpleMessagingGateway ?

    Hi,

    I have seen that SimpleMessagingGateway has been removed from the 2.0 release. What is the recommend approach to migrate if you wish to maintain exactly the same behaviour ?

  • #2
    Your question is perfectly timed to the last night's publishing of the Migration Guide http://www.springsource.org/node/2976

    This question is addressed there.
    Let us know if you need more info.

    Comment


    • #3
      I also want to mention (something I will add to the migration guide as well) is that one reason we removed SimpleMessagingGateway is that we extended the MessagingTemplate to cover request/reply behavior as well as delegation to MessageConverters, and much more. So, I would recommend first looking at MessagingTemplate to see if it meets your needs.

      Comment


      • #4
        Migrating from separate request/reply channels?

        I'm currently migrating some code over to Spring Integration 2.0. It is currently using a SimpleMessagingGateway with separate request/reply channels:

        Code:
        <si:channel id="requestChannel" />
        <si:channel id="replyChannel" />
        
        <beans:bean id="simpleMessagingGateway" class="org.springframework.integration.gateway.SimpleMessagingGateway" >
           <beans:property name="requestChannel" ref="requestChannel" />
           <beans:property name="replyChannel" ref="replyChannel" />
        </beans:bean>
        If I move to MessagingTemplate, it seems that you can only specify one channel. I assume that means that request and reply happen on the same channel. I further assume that MessagingTemplate understands how to differentiate between the two. Can I safely eliminate the use of two channels then?

        Thanks,

        Matt

        Comment


        • #5
          Matt

          No it is incorrect with regard to channels. Messaging Gateway is really the only component that encapsulates both Message Producer and Message Receiver so nothing really changed or will change from that perspective.

          What did change is SimpleMessagingGateway class was removed in 2.0 based on some major refactoring we did that greatly simplified the Messaging Gateway structure.
          So as of right now all you need to do is this:
          Code:
          MessageChannel requestChannel = ...;
          MessageChannel replyChannel = ...;
          GatewayProxyFactoryBean gatewayFactory = new GatewayProxyFactoryBean();
          gatewayFactory.setDefaultRequestChannel(requestChannel);
          gatewayFactory.setDefaultReplyChannel(replyChannel);
          gatewayFactory.afterPropertiesSet();
          requestReplyExchanger = (RequestReplyExchanger) gatewayFactory.getObject();
          The output object from the getObject() call will be RequestReplyExchanger which defines one simple method:
          Code:
          Message<?> exchange(Message<?> request);
          Hope that helps

          Comment


          • #6
            Matt,

            Actually, if you are just doing a simple request-reply, then I would recommend using one of the MessagingTemplate's sendAndReceive(..) methods. For example:
            Code:
            Message replyMessage = sendAndReceive(requestMessage);
            It doesn't use the *same* channel for request and reply, but rather it creates an anonymous reply channel that is set as a header on the request. It uses the template's defaultChannel property as the request channel (where it sends the request Message). The important point is that it waits on the reply channel so that you don't have to. You can also use one of the sendAndReceive methods that accepts the request channel (or channel name) as a parameter.

            The main reason we removed the SimpleMessagingGateway is that these request/reply operations were added to the MessagingTemplate itself.

            -Mark

            Comment


            • #7
              Thanks

              I'll try the MessagingTemplate approach first since it's less verbose. From reading the code, I don't think there's anything special about the reply channel. I'm thinking the team just specified both since SimpleMessagingGateway expected both.

              If that approach doesn't work, Oleg's looks like a good fallback strategy.

              -Matt

              Comment


              • #8
                MessagingTemplate worked great!

                Thanks guys.

                -Matt

                Comment


                • #9
                  Matt, out of curiosity, what did you end up doing? Raw template or proxy?

                  Comment


                  • #10
                    Here it is:

                    Config file:

                    Code:
                    <beans:bean id="messagingTemplate" class="org.springframework.integration.core.MessagingTemplate">
                       <beans:property name="defaultChannel" ref="requestChannel"/>
                    </beans:bean>
                    Java code:

                    Code:
                    Message<Map<String, Object>> checksumMessage = (Message<Map<String, Object>>) messagingTemplate.sendAndReceive(msg);

                    Comment

                    Working...
                    X