[英]Persist message in topic after server restart
我正在學習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>
我還讀到默認模式是持久的。 但就我而言,這似乎沒有用。
編輯:
根據加里·羅素在添加屬性后給出的答案
在<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”中。
請幫忙
默認情況下,這就是主題的工作方式,請閱讀JMS規范。
主題是發布/訂閱; 只有在場的訂戶才能接收到該消息。
如果發布5,請啟動使用者,再發布5;否則,請重新發布。 他只會得到第二個5。
如果您在經紀人全部拿走前殺死了經紀人5; 在重新啟動期間,代理發現沒有使用者,因此他清除了消息。
您可以通過使用持久訂閱來更改此行為,在這種情況下,代理確實會為每個此類訂閱保留消息,即使當前未連接也是如此。
要使用Spring Integration進行配置,請在消息驅動的通道適配器上設置subscription-durable
,並為其賦予唯一的subscription-name
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.