apache-camel - 如何使用 Apache Camel 从 ActiveMQ 主题中读取旧的入队消息
问题描述
我有 Apache Camel 客户端(消费者),它监听来自远程 ActiveMQ 主题的消息,我观察到它只在消费者运行时读取消息。
如果消费者没有收听并且生产者发送消息,它们将永远排队并由消费者选择。
我希望我的客户在启动时应该阅读所有排队的消息
public static void main(String[] args) throws Exception
{
ActiveMQComponent amq = new ActiveMQComponent();
amq.setConnectionFactory( new ActiveMQConnectionFactory() );
amq.setUsername("admin");
amq.setPassword("admin");
amq.setBrokerURL("tcp://localhost:8161");
Main main = new Main();
main.bind("activemq", amq);
main.addRouteBuilder(new MyRouter());
main.run(args);
}
以下是路由器代码
public void configure() throws Exception
{
from("activemq:topic:saadtopic")
.transform(simple(" ${body}"))
.to("stream:out");
}
ActiveMQ=5.15.9 ApacheCamel=2.24.1
解决方案
如果您没有使用持久订阅,并且您将消息发送到没有订阅者的主题,则该消息本质上将被丢弃,再也不会被看到。仅当存在具有离线订阅者的持久订阅并且消息被标记为持久时,代理才存储主题消息。
如果您希望能够访问在消费者关闭时发送的消息,那么您需要确保这些消费者至少运行一次并创建了持久主题订阅。
推荐阅读
- functional-programming - 简单机器学习标准中的递归
- git - 如何从其他人那里分叉我自己的存储库副本?
- javascript - Nodejs FS异步等待S3上传multer
- android - Jetpack Compose 中的 TextClock 等价物是什么?
- python - Mongo 获取一组键,包括嵌套的,以及相关的最近看到的日期
- automation - 如何在 Tosca 工具中对空值进行逐行比较
- list - Flutter:列表已弃用?
- vue.js - PrimeVue:表格列对齐不一致
- kotlin - 当函数成功执行完成时如何让 Kotlin “监听”
- ssrs-2012 - SSRS 报告 - 在报告中将 css/html/xml 格式字段显示为字符串或简单文本