消费者开始不经纪商

消费者开始不经纪商

本文介绍了ActiveMQ的:消费者开始不经纪商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个JMS客户端,从队列中消耗。我的经纪人是ActiveMQ的,如果它很重要。

I am writing a JMS client that consumes from a Queue. My broker is activemq, if it matters.

的一个要求是,如果代理是向下客户端应甚至开始。在这种情况下,它应该表现为,如果有其中的队列中没有消息,一旦券商和消息开始据此来行事。

One requirement is that the client should start even if the broker is down. In that case it should behave as if there where no messages in the Queue, and once the broker is up and messages start coming behave accordingly.

的问题是,在我的code:

The problem is that in my code:

connectionFactory = new ActiveMQConnectionFactory(url);
Connection connection = connectionFactory.createConnection();
connection.start()

如果券商关闭,则陷在 connection.start()。而我想有是 connection.start()来默默返回,并继续尝试在后台连接,虽然它可以消耗消息,保持沉默,当它不能。

If the broker is down, then it gets stuck in connection.start(). While what I would like to have is connection.start() to return silently and to continue to try to connect in the background and consume messages while it can and be silent when it can't.

我怎样才能做到这一点。

How can I achieve this.

推荐答案

使用单独的线程从队列中消费和启动连接。您将需要使用并发队列的实现。

Use separate threads for consuming from the queue and starting the connection. You will need to use a concurrent queue implementation.

主题1:


  • 实例化队列

  • 启动线程2

  • 尝试连接/块

  • 添加消息队列

主题2(或某种池):


  • 启动客户端

  • 从队列/块
  • 阅读
  • 处理消息

这篇关于ActiveMQ的:消费者开始不经纪商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:59