Soumya
Soumya

Reputation: 1054

Spring JMSTemplate - lost messages

We are using Spring JMSTemplate 3.0.1RELEASE to send JMS messages to an ActiveMQ cluster.

I am using useAsynSend=true to be able to send Asynchronous requests as these are all Fire and Forget. However they are still persistent and I can confirm they do get persisted on the AMQ Kaha-DB first and then forwarded on to Message Listeners. No CorelationID or JMSReplyTo as I am not listening back on any response.

   <amq:connectionFactory id="amqJmsFactory"
    brokerURL="failover:(tcp://MY-SERVER-01:61616,tcp://MY-SERVER-02:61616)?randomize=true&jms.useAsyncSend=true" />

<!-- JMS Producer Configuration -->
<bean id="jmsProducerTemplate" class="org.springframework.jms.core.JmsTemplate"
    p:connectionFactory-ref="amqJmsFactory" />

  <bean id="activeMQBinding" class="com.my.company.activemq.ActiveMQProductBinding">
    <property name="template" ref="jmsProducerTemplate" />
</bean>

In the ActiveMQProductBinding class we have the following method

  public void sendActiveMQMessageAsync(final Object message, String qName) {
    log.info("About to send message");
    template.send(qName, new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            ObjectMessage objectMessage = session.createObjectMessage((Serializable) message);

            log.info("Sending message: " + objectMessage);

            return objectMessage;
        }
    });
}

Now I can see in the logs that the logs are getting printed. No Exception is thrown. Still some messages are totally getting lost. It probably doesn't reach ActiveMQ. I have Mule JMS Listeners configured to listen to messages on the ActiveMQ queues defined by 'qName' above. Most of the messages get delivered to AMQ fine and Mule picks them up within fraction of a second. However it is only some messages which are getting lost. When I checked the Queues on ActiveMQ I can see all messages received have been dispatched fine to Mule. Hence I am suspecting the messages aren't reaching ActiveMQ at all or AMQ is rejecting. However no logs on JMSTemplate spring or ActiveMQ.

The Message created looks like this (It is printed in the method above).

   2013-03-11 16:33:11,752 INFO [com.my.company.activemq.ActiveMQProductBinding$1] Sending message: ActiveMQObjectMessage {commandId = 0, responseRequired = false, messageId = null, originalDestination = null, originalTransactionId = null, producerId = null, destination = null, transactionId = null, expiration = 0, timestamp = 0, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = false, type = null, priority = 0, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@61408493, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = false, readOnlyBody = false, droppable = false}

Anything I am missing on JMSTemplate config or some behaviour on AMQ? Please help!

Any help guys?

Upvotes: 1

Views: 3732

Answers (1)

Soumya
Soumya

Reputation: 1054

2 Possible reasons I can think of. 1) We are using the wrong connection factory. We should use Pooled Connection Factory with JMSTemplate to send messages. org.apache.activemq.pool.PooledConnectionFactory

2) We are using useAsyncSend=true - i.e. the sender sends the message and does not wait for acknowledgement and there are chances of message losses. This seems more probable but not sure.

Still not accepting this as Answer as someone may have a more concrete explanation. In the meantime if anyone stumbles upon this question may be benefitted by this cues.

Upvotes: 1

Related Questions