ActiveMQ: launching a consumer without a broker

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

One of the requirements is that the client must get started, even if the broker is not working. In this case, he should behave as if there are no messages in the queue, and as soon as the broker gets up and the messages begin to arrive accordingly.

The problem is that in my code:

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

If the broker is off, it gets stuck in connection.start(). Although I would like to connection.start()return silently and continue to try to connect in the background and consume messages while he can, and be silent when he cannot.

How can i achieve this.

+3
source share
5 answers

Use separate threads to consume from the queue and start the connection. You will need to use a parallel implementation of the queue.

Theme 1:

  • Queue creation
  • Start topic 2
  • Try to connect / block
  • Add messages to the queue

Topic 2 (or some kind of pool):

  • Launch client
  • Reading from the queue / block
  • Message processing
+1
source

There are two ways to get around this type of scenario, one of which is described in AMQ-2114:

  • Using the broker URI that was proposed in AMQ-2114. Using the broker URI, which is offered in AMQ-2114, an embedded broker is created with a network connection to a remote broker. However, as indicated, this URI broker does not use a failover connector.

  • , . , ActiveMQ Java- . . , (.. ). , .

, , Java- . , . Java, , . , , .

+1

, Spring DefaultMessageListenerContainer , :

<jms:listener-container>
    <jms:listener destination="queue.orders" ref="orderService" method="placeOrder"/>
</jms:listener-container>

jms ( JMS , , ).

+1

, ActiveMQ ( ....), . "failover://" - URL- , .

0

. . AMQ-2114.

, .

++- ActiveMQ. , .

I thought of calling connection.start () on a separate thread and calling and calling connection-> createSession () in TransportListener :: transportResumed (). But createSession hangs up.

On the bottom line, I do not have a working solution, and I am glad to know another solution to the problem.

0
source

Source: https://habr.com/ru/post/1777433/


All Articles