Announcement Announcement Module
No announcement yet.
Acknowledge message on the Client by using Spring Integration Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Acknowledge message on the Client by using Spring Integration


    I have spring configuration:

    <int:gateway id="gatewayAsynchService" service-interface="pl.firstdata.maqc.integration.GatewayAsynchService" >
            <int:method name="process" request-channel="requestChannel" />
        <int:poller default="true" fixed-delay="250"/>
        <int:channel id="requestChannel">
            <int:dispatcher task-executor="simpleAsyncTaskExecutor"/>
        <bean id="simpleAsyncTaskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
        <int-jms:outbound-gateway request-channel="requestChannel" request-destination="requestQueue"
        <int-jms:message-driven-channel-adapter acknowledge="client" id="mdChannel" connection-factory="connFactory"
                                                destination="replyQueue" channel="replyChannel" />
        <int:outbound-channel-adapter id="replyChannel" ref="integrationAsynchService" method="logMessage"  />
        <bean id="integrationAsynchService" class="pl.firstdata.maqc.integration.IntegrationAsynchService"/>
        <jee:jndi-lookup id="requestQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/req"/>
        <jee:jndi-lookup id="replyQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/reply"/>
        <bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="jms/RemoteConnectionFactory"/>
        <bean id="connFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
            <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/>
            <property name="username" value="robert"/>
            <property name="password" value="sys"/>
    In message-driven-channel-adapter I have acknowledge="client" and that's works so that when no runtime exception is thrown in outbound-channel-adapter method (logMessage) than every message is consumed. When runtime exception is thrown then messages that wasn't delivered are not lost and remain in a queue. That's fine, but I would like to have possibility to steer with it for instance by invoking message.acknowledge();
    I would like not to acknowledge process untill I get all messages for example.

    How can I do it by using Spring Integration in a client?

  • #2
    If you set 'extract-payload="false"' on the message-driven adapter, the payload of the message sent to 'replyQueue' will be the (unconverted) JMS Message.


    • #3
      Thank you Gary for reply!

      I have noticed that when I (in the above example) set acknowledge="client" then the messages are not lost when the method logMessage in IntegrationAsynchService throw RuntimeException and messages remain in the queue. The messages are removed from the queue only then when the method ends successfully. That's great.

      I don't acknowledge messages by message.acknowledge().
      It looks like the invoke message.acknowledge() is not necessary. Does SI automatically acknowledge messages when they are received in client without error?

      I would be grateful for any hint what is a recommended way to do in this case in order to prevent messages loss (if I do something wrong)
      Last edited by RobertVox1977; Feb 20th, 2013, 08:32 AM.


      • #4
        Sorry - yes, I forgot that the listener container (used by the adapter) acks the message when the thread returns normally.

        So, no, there is no way to "batch" the acks using standard components. You would have to use a custom adapter that uses JMS (or Spring JMS) at a lower level.


        • #5
          That behaviour is guite good for me.

          Now I'm sure how it works. Thanks a lot Gary!