2013-03-12 181 views
1

我们使用Spring JMSTemplate 3.0.1RELEASE将JMS消息发送到ActiveMQ集群。Spring JMSTemplate - 丢失的消息

我正在使用useAsynSend = true来发送异步请求,因为这些都是Fire和Forget。但是它们仍然是持久的,我可以确认它们首先保持在AMQ Kaha-DB上,然后转发到Message Listeners。没有CorelationID或JMSReplyTo,因为我没有收听任何回应。

<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> 

在ActiveMQProductBinding类,我们有以下方法

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; 
     } 
    }); 
} 

现在我可以在越来越打印日志中的日志中看到。不引发异常。还有一些消息完全丢失。它可能没有达到ActiveMQ。我将Mule JMS Listeners配置为侦听上面由'qName'定义的ActiveMQ队列中的消息。大部分消息都传递给了AMQ,而且Mule会在几秒钟内将它们捡起来。然而,它只是一些消失的消息。当我查看ActiveMQ上的队列时,我可以看到收到的所有消息都已经发送给Mule。因此我怀疑这些消息根本没有到达ActiveMQ,或者AMQ拒绝。但是JMSTemplate spring或ActiveMQ没有日志。

创建的消息看起来像这样(它在上面的方法中打印)。

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 = [email protected], marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = false, readOnlyBody = false, droppable = false} 

任何我缺少的JMSTemplate配置或AMQ上的一些行为?请帮忙!

任何帮助家伙?

+0

我想,缺少的消息是在其他经纪人,它没有被消耗。 – techuser 2013-03-14 04:45:06

+0

嗨..你可以多说一点吗? – Soumya 2013-03-14 10:37:23

+0

我的建议是检查两个经纪人的消息数量,因为您使用启用随机启动的故障转移连接,并确保消费者实际上都从这两个经纪人消费。 – techuser 2013-03-14 13:36:54

回答

1

2可以考虑的原因。 1)我们使用错误的连接工厂。我们应该使用Pooled Connection Factory和JMSTemplate来发送消息。 org.apache.activemq.pool.PooledConnectionFactory

2)我们使用useAsyncSend = true - 即发送者发送消息,并且不等待确认并且有消息丢失的机会。这似乎更可能但不确定。

仍然不接受这个答案,因为某人可能有更具体的解释。与此同时,如果有人绊倒这个问题可能会受益于这个线索。