首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring JMSTemplate -丢失的消息

Spring JMSTemplate -丢失的消息
EN

Stack Overflow用户
提问于 2013-03-12 18:46:51
回答 1查看 3.1K关注 0票数 1

我们使用SpringJMS3.0.1RELEASE向ActiveMQ集群发送JMSTemplate消息。

我使用useAsynSend=true来发送异步请求,因为这些都是“即发即忘”。然而,它们仍然是持久的,我可以确认它们确实首先在AMQ Kaha-DB上持久存在,然后转发到消息侦听器。没有CorelationID或JMSReplyTo,因为我没有在监听任何响应。

代码语言:javascript
复制
   <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类中,我们有以下方法

代码语言:javascript
复制
  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 fine,Mule会在不到一秒的时间内将它们提取出来。然而,只有一些消息正在丢失。当我检查ActiveMQ上的队列时,我可以看到所有收到的消息都被很好地分派到了Mule。因此,我怀疑这些消息根本没有到达ActiveMQ,或者AMQ正在拒绝。然而,在JMSTemplate spring或ActiveMQ上没有日志。

创建的消息如下所示(它在上面的方法中打印)。

代码语言:javascript
复制
   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的配置或者行为上有什么遗漏吗?请帮帮我!

有帮手吗?

EN

回答 1

Stack Overflow用户

发布于 2013-03-28 00:55:57

我能想到的两个可能的原因。1)我们使用了错误的连接工厂。我们应该使用带有JMSTemplate的池化连接工厂来发送消息。org.apache.activemq.pool.PooledConnectionFactory

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

仍然不接受这个答案,因为有些人可能有更具体的解释。同时,如果有人偶然发现了这个问题,可能会从这个线索中受益。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15359098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档