【发布时间】:2013-02-27 20:10:08
【问题描述】:
我们正在使用 Spring JMSTemplate 3.0.1RELEASE 将 JMS 消息发送到 ActiveMQ 集群。
我使用 useAsynSend=true 来发送异步请求,因为这些都是 Fire and Forget。但是它们仍然是持久的,我可以确认它们确实首先在 AMQ Kaha-DB 上持久化,然后转发到消息侦听器。没有 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 侦听器配置为侦听上面由“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 = org.apache.activemq.util.ByteSequence@61408493, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = false, readOnlyBody = false, droppable = false}
我在 JMSTemplate 配置或 AMQ 上的某些行为中缺少什么?请帮忙!
有帮助吗?
【问题讨论】:
-
我猜,丢失的消息在另一个代理上,没有被消费。
-
嗨..抱歉,您能详细说明一下吗?
-
我的建议是在您使用启用了随机化的故障转移连接时检查两个代理上的消息数,并确保消费者实际上是从两个代理消费的。
-
是的。任何到达 2 的东西也会被听众拾起。基本上它似乎根本没有达到 AMQ。
标签: jms activemq messaging spring-jms jmstemplate