Broker URL
failover:(tcp://broker1:61616,tcp://broker2:61616)?randomize=false&jms.useAsyncSend=false&jms.dispatchAsync=false&maxReconnectAttempts=2&maxReconnectDelay=100
I register a message listener on the active broker:
Destination destQueue = new ActiveMQQueue("queue");
MessageConsumer messageConsumer = session.createConsumer(destQueue);
messageConsumer.setMessageListener(consumer);
During a failover the consumer disapears and is not re-registered on the second broker. Can you give me some light how could I register the listener on the other broker automatically upon failover?
thanks in advance
Found out - the problem was because I used PooledConnectionFactory for listener's code. Replaced with ActiveMQConnectionsFactory and it worked.
Related
Is there a way to create a RabbitMQ queue using spring cloud stream without having a consumer for the queue.
Our scenario is that we want to use the delay messaging strategy, so messages coming to the first queue would be held until expired and moved to a DLQ.
The application would be consuming the messages from the DLQ.
Wanted to check if there is a way we can use spring cloud stream to configure the queues, when we do not have a consumer for the first queue and it's just there to hold messages till expiry.
Yes; simply add a Queue bean (and binding if needed).
Boot auto configures a RabbitAdmin which will detect such beans when the connection is first established.
https://docs.spring.io/spring-amqp/docs/current/reference/html/#broker-configuration
#Bean
public Queue queue() {
return QueueBuilder.nonDurable("foo")
.autoDelete()
.exclusive()
.withArgument("foo", "bar")
.build();
}
I need to start a queue in OpenEJB in a "paused" state so no messages are processed by the consumer until some related data is available. I can programmatically pause the queue as shown here, so if there was some initializer function that is called when a queue is created I could use that method. The queue configuration documentation does not seem to support setting the paused state. Any ideas on how to configure the queue upon creation?
If you read the thread you link you will see a queue is not paused but a broker can be.
In TomEE broker is created from a factory using a spi (in tomee classloader so tomee/lib by default) so you can write your own if that's an option starting programmatically when you are ready.
Now I suspect you don't want to start connectors with the container but it is not an issue to start the broker. Said otherwise you don't want to be connected to any other machine through JMS to not receive anything but if JMS is started and deployed it is ok.
In such a case you can just not configure any connector on the broker and add them when ready. You can find brokers doing:
new org.apache.openejb.resource.activemq.ActiveMQ5Factory().getBrokers()
We have a requirement, where we create queues in rabbitMq on application startup with direct exchange, and then have to assign a single listener to each queue. We implemented that using Spring AMQP with the following configuration
#Bean(name= {"dispatcherListener"})
public SimpleMessageListenerContainer dispatcherListener() {
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
listenerContainer.setConnectionFactory(connectionFactory());
listenerContainer.setQueues(participantQueues());
listenerContainer.setMessageConverter(jsonMessageConverter());
listenerContainer.setMessageListener(subscriptionListener);
listenerContainer.setAcknowledgeMode(AcknowledgeMode.AUTO);
listenerContainer.setAutoStartup(false);
return listenerContainer;
}
But then we faced a problem, with the above configuration. When we publish the message to multiple queues , then the listener is reading the messages serially from each queue. But we expected it to listen to messages from each queue independent of other queue parallely.
Can someone please guide me, where i went wrong ?
Any help would be appreciated
That's correct behavior, since the default concurrency is 1, therefore we have only one listener for all queue.
Just consider to increase that value for your configuration.
More info in the Reference Manual.
The following is my ActiveMQ setup:
I have two AMQ broker which are configured with failover.
I have 40 producer but only on consumer.
Now the problem:
From time to time, one of the producer lost the connection to the master broker. The failover reacts and the producer gets a new connection to the slave which gets the messages. So far so good. But the consumer does not have the problem, he consumes still the messages from the master. He does not know, that the slave has also some messages.
How can i now solve the problem woth losing those messages thay are sent to the slave?
Thank in advance
I would recommend you configure a network of brokers. That way, your brokers will be connected as well, and it no longer matters which broker your producers and consumers connect to - the messages will get propagated across the network.
I am new to Stomp ActiveMQ. I want to create a login from an android client and I don't know how to use ActiveMq. I\ve installed active mq, configured stomp and run the stompexample.
1. I have an error when running activemq from command line if I add in in the activemq.xml the following line:
<transportConnector name="stomp+nio" uri="stomp+nio://localhost:61612"/>
<transportConnector name="stomp+ssl" uri="stomp+ssl://localhost:61612"/>
Can someone please explain what is with tx1 and tx2? Is there a way to send on the queue a message to a specific client? how?
connection.connect("system", "manager");
connection.begin("tx1");
connection.send("/queue/test", "message1");
connection.send("/queue/test", "message2");
connection.commit("tx1");
connection.subscribe("/queue/test", Subscribe.AckModeValues.CLIENT);
connection.begin("tx2");
StompFrame message = connection.receive();
System.out.println(message.getBody());
connection.ack(message, "tx2");
message = connection.receive();
System.out.println(message.getBody());
connection.ack(message, "tx2");
connection.commit("tx2");
connection.disconnect();
Can someone please tell me how to create an application that sends on a queue a text containing username, password and receives an answer if the register was successful?
You need to configure the transport connectors with different port numbers, they can't both share port 61612. Your configure is create a Stomp NIO connector and a different Stomp SSL Connector.
You can't send messages to a distinct client, you just place them on a Queue and if there is a client subscribed it will get the message, that's the nature of Queue based messaging. The TX1 TX2 stuff is sending the messages within a transaction.
Recommend you take some time to read up of JMS Messaging, the Stomp spec and some other messaging based tutorials.