【发布时间】:2016-01-13 18:48:40
【问题描述】:
我正在学习 Spring Integration JMS。我遇到了一个问题,即我的主题没有保留尚未被客户端使用的待处理消息。
基本上我启动 ActiveMQ 然后使用 REST 客户端我调用生产者发送消息 50 次,以便 50 条消息在主题中排队。在消费者端,我应用了 5 秒的睡眠计时器,以便每条消息以 5 秒的固定间隔被消耗。然后在这之间我停止了 ActiveMQ。同时,客户端消费了一些消息,假设 50 条消息中有 15 条已被消费。然后,如果我重新启动 ActiveMQ,我希望主题会保留 35 条待处理的消息,但我在管理控制台中的主题选项卡下看不到。
这是我的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:int-jme="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
<!-- Component scan to find all Spring components -->
<context:component-scan base-package="com.geekcap.springintegrationexample" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="order" value="1" />
<property name="messageConverters">
<list>
<!-- Default converters -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</list>
</property>
</bean>
<!-- Define a channel to communicate out to a JMS Destination -->
<int:channel id="topicChannel"/>
<!-- Define the ActiveMQ connection factory -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<!--
Define an adaptor that route topicChannel messages to the myTopic topic; the outbound-channel-adapter
automagically fines the configured connectionFactory bean (by naming convention
-->
<int-jms:outbound-channel-adapter channel="topicChannel"
destination-name="topic.myTopic"
pub-sub-domain="true" />
<!-- Create a channel for a listener that will consume messages-->
<int:channel id="listenerChannel" />
<int-jms:message-driven-channel-adapter id="messageDrivenAdapter"
channel="getPayloadChannel"
destination-name="topic.myTopic"
pub-sub-domain="true" />
<int:service-activator input-channel="listenerChannel" ref="messageListenerImpl" method="processMessage" />
<int:channel id="getPayloadChannel" />
<int:service-activator input-channel="getPayloadChannel" output-channel="listenerChannel" ref="retrievePayloadServiceImpl" method="getPayload" />
</beans>
我还读到默认模式是持久的。但就我而言,它似乎不起作用。
编辑:
根据Gary Russel在添加属性后给出的答案
- subscription-durable="true"
- durable-subscription-name="mySubscription"
在<int-jms:message-driven-channel-adapter> 我遇到了与 XML 相关的问题
cvc-complex-type.3.2.2:属性“subscription-durable”不允许出现在元素“int-jms:message-driven-channel-adapter”中。
-
cvc-complex-type.3.2.2:属性“durable-subscription-name”不允许出现在元素“int-jms:message-driven-channel-adapter”中。
请帮忙
【问题讨论】:
-
到目前为止你做了什么来尝试解决你的问题?
-
我在activemq.xml的
标签中添加了 persistent=true。 -
进一步我尝试在从频道发送消息时像这样设置
MessageBuilder .withPayload(ticket) .setHeader(AmqpHeaders.DELIVERY_MODE, MessageDeliveryMode.PERSISTENT) .build();
标签: java jms activemq spring-integration