Announcement Announcement Module
No announcement yet.
Active MQ - Ack on successfully posting a message onto the Queue/Topic Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Active MQ - Ack on successfully posting a message onto the Queue/Topic

    Hi Team,
    Have a scenario where in i need to check that the message was posted successfully onto the Destination Queue/Topic using ActiveMQ.

    Below mentioned is the JMS configuration , appreciate if somebody could guide me achieve an acknowledgement kind of functionality, from the destination Queue/Topic.

    <!-- Inbound Connection Factory --> 
            <bean id="inboundJmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> 
                    <property name="brokerURL" value="${int.actmq.jms.connectionfactory}" /> 
            <!-- jms:message-driven-channel-adapter - Defines a JMS Message-Driven inbound 
                    Channel Adapter --> 
                    connection-factory="inboundJmsFactory" destination-name="${int.jms.inbound.queue}" 
                    channel="com.hcl.jms.inbound" extract-payload="true" /> 
            <!-- Outbound Connection Factory --> 
            <bean id="outboundJmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> 
                    <property name="brokerURL" value="${int.actmq.jms.connectionfactory}" /> 
            <!-- jms:outbound-channel-adapter - Defines an outbound JMS Message-sending 
                    Channel Adapter --> 
                    destination-name="${int.jms.outbound.queue}" connection-factory="outboundJmsFactory" 
                    channel="com.hcl.jms.outbound" extract-payload="true" />
    Properties -

  • #2
    I moved this thread the AMQP forum is for AMQP not ActiveMQ (JMS).

    If you inject a JmsTemplate bean (with sessionTransacted=true) into the outbound adapter (jms-template attribute), then ActiveMQ will guarantee the send results in the message being secured in the queue because the template will commit the transaction.


    • #3
      Hi Gary,
      Thanks for the reply.
      Is there a possibility to do this without using a JMS Template?

      Had come across a post on Dzone saying not to use JMS Template.


      • #4
        The adapter uses a JmsTemplate internally; by declaring it externally it just gives you more options for configuration, such as setting sessionTransacted.

        Gordon is simply advising folks they don't need to use a JmsTemplate directly any more; I am not suggesting anything different.


        • #5
          Hi Gary, thanks for the clarification.
          Will try that out and come back with my findings.


          • #6
            Receive the acknowlede message onto the reply-channel

            Hi Gary, as per the requirement - Need to get an acknowledgment saying , Posted successfully onto Queue - [queuename], parse the reply and save it onto a database.[Business requirement to state the message was posted successfully on time]

            Is this possible through Spring Integration?

            As you suggested - sessionTransacted=true , this will make sure the message is posted onto the queue, else throw exception, am i right?
            But how can we persist the data saying the message was successfully posted onto the queue?

            I was looking at the <int-jms:outbound-gateway> adapter, can the ack message be received by the reply-channel?
            Any other setting of parameter to receive the ack onto the reply-channel?

            Please correct me if I'm wrong.



            • #7
              <int:publish-subscribe-channel id="foo"/>
              <int-jms:outbound-channel-adapter channel="foo" order="1" .../>
              <int:chain input-channel="foo" order="2">
                  <int:transformer expression="'successfully posted:' + payload" />
                  <int-jdcb:outbound-channel-adapter ... />
              The chain will only be invoked if the jms operation was successful.

              Alternatively, add an ExpressionEvaluatingRequestHandlerAdvice to the jms adapter; then you can add "onSuccess" and "onFailure" expressions to take different actions. The the reference manual and the "retry-and-more" sample for more information about this technique.


              • #8
                Perfect, Thanks Gary!

                Will implement this and share my findings. Thanks for your time.



                • #9
                  Hi Gary,
                  Found this from the standard JMS API on oracle site. This is exactly what the client is looking for.


                  public QueueSession createQueueSession(boolean transacted,
                  int acknowledgeMode)

                  throws JMSException

                  Creates a QueueSession object.

                  transacted - indicates whether the session is transacted
                  acknowledgeMode - indicates whether the consumer or the client will acknowledge any messages it receives; ignored if the session is transacted. Legal values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, and Session.DUPS_OK_ACKNOWLEDGE.
                  a newly created queue session
                  JMSException - if the QueueConnection object fails to create a session due to some internal error or lack of support for the specific transaction and acknowledgement mode.
                  See Also:
                  Aim: Get whatever acknowledgement we receive when we successfully post the message onto the Destination Queue. I.e acknowledgement message provided by the JMS provider or client.

                  Can we implement the same through <int-jms:outbound-channel-adapter> ?

                  Appreciate yours advice on the same.


                  • #10
                    You are mis-understanding that JavaDoc; that is for RECEIVING messages and the behavior of the receiving client in terms of how it tells the broker that it can now discard the message because it's been delivered.

                    In JMS there is NO acknowledgment sent to a SENDING client; as I said above, you don't need one; when using a transactional session, if the commit succeeds, the broker guarantees that the message has been deposited.

                    In Spring Integration this means that if the send to the channel succeeds (no exception), then the broker has the message; hence, adding another subscriber to the channel as I described above, when the message arrives at that subscriber, the JMS operation can be treated as 'success'.


                    • #11
                      Hi Gary,
                      Thanks a lot for the explanation.

                      I happened to play around with the jmsTemplate configurations and noticed i'm getting something as reply from the Dbus Queue.

                      Config -
                      <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> 
                                      <property name="connectionFactory" ref="authenticationConnectionFactory" /> 
                                      <property name="destinationResolver" ref="jmsDestinationResolver" /> 
                                      <property name="defaultDestination" ref="destination" /> 
                                      <property name="sessionAcknowledgeModeName" value="client_acknowledge" /> 

                      Can you please confirm if this is an acknowledgement?

                      [24.07.2013 09:09:17] INFO: LoggingHandler.handleMessageInternal() - <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE GMAadapter SYSTEM "GMAadapter_1_4.dtd"><GMAadapter><GMAadapterHe ader version="1.4.1"><GMAGlobal><RelatedReferenceKey>OI Q03079921015</RelatedReferenceKey><MsgType>202</MsgType><MsgFormat>sw</MsgFormat></GMAGlobal><MessageOwner><CustomerName>GAZPROMBANK</CustomerName><Department>AMIQSDEU</Department><CostCentre>851-235</CostCentre><OriginatorApplication>IQS</OriginatorApplication><OriginatorApplicationSequen ceNo>21015</OriginatorApplicationSequenceNo></MessageOwner><PaymentInformation><ValueDate>130703 </ValueDate><Currency>USD</Currency><Amount>3393251,36</Amount></PaymentInformation><Status><DeliveryDate>130703</DeliveryDate><DeliveryTime>2010</DeliveryTime><TestkeyAuthResult>C</TestkeyAuthResult></Status><Regional><DuplicateCheckOverride>D</DuplicateCheckOverride></Regional></GMAadapterHeader><GMAadapterBody>{1:F01DEUTSGSGAXX X0000021015}{2:I202BKTRUS33AXXXN}{3:{108:21015}}{4 :&#xD;
                      :72:/BNF/001-51141 Account No&#xD;
                      //9972000013 Gazprombank&#xD;


                      • #12
                        The acknowledge mode has no bearing when using a JmsTemplate to SEND, only when RECEIVing.

                        Since I don't know your configuration, I don't know what it is; if you are using the suggestion I made, and hooked up the channel to a logging adapter, it's the message that was sent.


                        • #13
                          In JMS there is NO acknowledgment sent to a SENDING client

                          Ah, as always, you were right, that was the data polled from the database
                          Just double checked it and confirmed.

                          Thanks for clearing my queries Gary! Appreciate it!