Jms 跨服务器重启在ActiveMQ中持久化消息
我正在学习Spring集成JMS。因为ActiveMQ是一个消息代理。我指的是这里给出的项目-> 但我想知道如何在ActiveMQ中持久化消息。我的意思是我启动了ActiveMQ,然后使用REST客户端发送请求。我正在呼叫Jms 跨服务器重启在ActiveMQ中持久化消息,jms,activemq,spring-integration,message-queue,spring-jms,Jms,Activemq,Spring Integration,Message Queue,Spring Jms,我正在学习Spring集成JMS。因为ActiveMQ是一个消息代理。我指的是这里给出的项目-> 但我想知道如何在ActiveMQ中持久化消息。我的意思是我启动了ActiveMQ,然后使用REST客户端发送请求。我正在呼叫publishService.send(message)在for循环中运行50次,接收器端的睡眠计时器为10秒。使50条消息排队,并以10秒的间隔开始处理 编辑: 请看下面的屏幕截图: 它说有50条消息排队,其中5条已经被取消排队 但在此期间,我停止了ActiveMQ服务器,
publishService.send(message)代码>在for循环中运行50次,接收器端的睡眠计时器为10秒。使50条消息排队,并以10秒的间隔开始处理
编辑:
请看下面的屏幕截图:
它说有50条消息排队,其中5条已经被取消排队
但在此期间,我停止了ActiveMQ服务器,当它消耗了50条消息中的5条时,再次重新启动它
但我希望它在Messages Enqueue列中显示剩余的45条消息。但我可以在那里看到0(见下面的屏幕截图),它们在服务器重启后都消失了,而不必保留剩余的45条消息。我怎样才能克服这个问题
请查看以下配置:
<?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>
通过进一步搜索,我发现根据JMS规范,默认的交付模式是持久的。但在我的例子中,它似乎不起作用
请帮助我进行正确的配置,以便消息可以在代理失败时持久化 这通常不是问题,而是activeMQ的构建方式
您可以在“ActiveMQ正在运行”一书中找到以下解释
- 一旦消息已被消息使用并确认
消费者,它通常从代理的消息存储中删除
因此,当您重新启动服务器时,它只显示代理消息存储中的消息。在大多数情况下,您永远不需要查看已处理的消息
希望这有帮助
祝你好运 谢谢你的回复。你让我明白了概念。事实上,我的想法是错误的。我不想持久化已消费的消息,而是希望ActiveMQ持久化服务器崩溃后消费者尚未消费的剩余消息。我已经更新了问题。请看一下。您能看一下标记中的“activemq.xml”吗?是否指定了类似“persistent=false”的内容?如果是,则将其更改为pesistent=trueNo我在activemq.xml中找不到persistent=false
,这就是我的
标签的外观
我是否应该添加pesistent=true
like,使其看起来
@Erik Williams你能帮我一下吗?@Tim Bish你能为我指出正确的方向吗?
@Controller
public class MessageController
{
@Autowired
private PublishService publishService;
@RequestMapping( value = "/message", method = RequestMethod.POST )
@ResponseBody
public void postMessage( @RequestBody com.geekcap.springintegrationexample.model.Message message, HttpServletResponse response )
{
for(int i = 0; i < 50; i++){
// Publish the message
publishService.send( message );
// Set the status to 201 because we created a new message
response.setStatus( HttpStatus.CREATED.value() );
}
}
}
@Service
public class MessageListenerImpl
{
private static final Logger logger = Logger.getLogger( MessageListenerImpl.class );
public void processMessage( String message )
{
try {
Thread.sleep(10000);
logger.info( "Received message: " + message );
System.out.println( "MessageListener::::::Received message: " + message );
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}