【问题标题】:How to read old Enqueued messages from ActiveMQ Topic with Apache Camel如何使用 Apache Camel 从 ActiveMQ 主题中读取旧的入队消息
【发布时间】:2019-11-17 07:43:29
【问题描述】:

我有 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

【问题讨论】:

标签: apache-camel jms activemq


【解决方案1】:

如果您没有使用持久订阅,并且您将消息发送到没有订阅者的主题,则该消息基本上会被丢弃,再也不会被看到。仅当存在具有离线订阅者的持久订阅并且消息被标记为持久时,代理才存储主题消息。

如果您希望在消费者关闭时访问发送的消息,那么您需要确保这些消费者至少运行一次并创建了持久主题订阅。

【讨论】:

    猜你喜欢
    • 2016-06-20
    • 1970-01-01
    • 2017-05-05
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多