Consumer can't receive messages even though usePrefetchExtension is true - activemq

If usePrefetchExtension is true(default), I think number of messages over prefetchSize are sent to a consumer.
I tried the following.
ActiveMQ Version : 5.15.13
activemq.xml :
<policyEntry>
<policyEntry queue=">" usePrefetchExtension="true" queuePrefetch="1">
</policyEntry>
consumer.sh options :
--ackMode CLIENT_ACKNOWLEDGE
--batchSize 10
--sleep 10000
After 100 messages are sent from a producer, consumer.sh is executed.
I think 10 messages (=batchSize) are sent to a consumer.
But, after one message is sent, any other messages aren't sent.
The following is shown at Active Consumers Menu of web console.
Do I misunderstand the meaning of usePrefetchExtension?
Enqueues : 1
Dequeues : 0
Dispatched : 1
Dispatched Queue : 1

Related

ActiveMQ consumer timed out

We are facing problem of ActiveMQ consumer timedout for one of our Queue(ServiceResponses). This problem started to occur after a couple of days. Here are Queues information from one Node AMQ.
Number of Consumers for Response Queue either 0 or 1 and also Number of Pending Messages exist on this Queue and seem to grow with time.
JMSTemplate with connection pooling(jms-pool) is being used for send and receive. Here is the code snippet which sends to request queue and receive from response queue
val out = mc.andThen { msg =>
msg.setJMSType(mt.jmsType)
msg.setJMSCorrelationID(correlationId)
msg.setJMSReplyTo(responseQueue)
msg
}
jmsTemplate.send(requestQueue, out)
jmsTemplate.setReceiveTimeout(timeoutInMillies)
val response = jmsTemplate.receiveSelected(responseQueue, s"JMSCorrelationID = '$correlationId'")
Timeout value is 5 seconds.
Client Connection Settings are:
spring.activemq.broker-url=failover:(ssl://HOST1:PORT?keepAlive=true&connectionTimeout=500&soTimeout=360000,ssl://HOST2:PORT?keepAlive=true&connectionTimeout=500&soTimeout=360000)?initialReconnectDelay=10&maxReconnectDelay=9000&randomize=true&timeout=1000&backup=false&priorityBackup=true
Does anyone has idea what could be the reason and how can we fix this problem?

How to use same message header id in queue?

I want to use the Message Header ID generated in Queue 1 to Queue 2.
Can you please tell me how to achieve this in ActiveMQ?
Scenario:
Queue 1 message was not processed by ESB bus due to some failure
We will be using Queue 2 to post the message again after fixing it with
the same Message Header ID created in Queue 1
Queue 1 (Process):
Message Header ID : ID:XYZ-1234-1555664319032-4:2:1:1:1
Queue 2 (Re-process):
Message Header ID : ID:XYZ-1234-1555664319032-4:2:1:1:1
Many Thanks,
Samuel
ActiveMQ itself assigns the message IDs. It's not something which can be done from a client application. You'll need to use a different message header or property for your application-specific ID.

Spring AMQP- How does i retry/re-queue message from DLX queue to original queue?

i am trying to implement below scenario in my application
Exachange e1 -> Queue q1
DLX exchange e2 -> Queue q2
Also i have mentioned DLE and DLK in queue-q1 then message moving to queue-q2 on rejection/failure/timeout.
But how does i resend/retry message from queue-q2 to original queue-q1?
You can do that manually in your application after some analyze and filtering logic. Or you can make some TTL on that queue-q2 to let not consumed messages to be expired. And you also need to specify in this queue a x-dead-letter-exchange as a name for the Exachange e1 for desired recycling.
See more info yin this article:
Create the dead letter exchange, which is just a normal exchange with a special name
Create a retry_message queue and have all messages published to the dead letter exchange route here
When you setup the retry_message queue, be sure to default the following parameter values of the queue
x-message-ttl: 30000 – This will set a ttl on any message published to the queue. When the ttl expires, the message will be republished to the exchange specified in the x-dead-letter-exchange parameter.
x-dead-letter-exchange: original_exchange_name – This is where the message will get republished to once the message ttl expires. We normally want this be the name of the exchange where the message was originally published.

In RabbitMQ how to consume multiple message or read all messages in a queue or all messages in exchange using specific key?

I want to consume multiple messages from specific queue or a specific exchange with a given key.
so the scenario is as follow:
Publisher publish message 1 over queue 1
Publisher publish message 2 over queue 1
Publisher publish message 3 over queue 1
Publisher publish message 4 over queue 2
Publisher publish message 5 over queue 2
..
Consumer consume messages from queue 1
get [message 1, message 2, message 3] all at once and handle them in one call back
listen_to(queue_name , num_of_msg_to_fetch or all, function(messages){
//do some stuff with the returned list
});
the messages are not coming at the same time, it is like events and i want to collect them in a queue, package them and send them to a third party.
I also read this post:
http://rabbitmq.1065348.n5.nabble.com/Consuming-multiple-messages-at-a-time-td27195.html
Thanks
Don't consume directly from the queue as queues follow round robin algorithm(an AMQP mandate)
Use shovel to transfer the queue contents to a fanout exchange and consume messages right from this exchange. You get all messages across all connected consumers. :)
If you want to consume multiple messages from specific queue, you can try as below.
channel.queueDeclare(QUEUE_NAME, false, false,false, null);
Consumer consumer = new DefaultConsumer(channel){
#Override
public void handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties properties,
byte[] body)
throws IOException {
String message = new String(body, "UTF-8");
logger.info("Recieved Message --> " + message);
}
};
You might need to conceptually separate domain-message from RMQ-message. As a producer you'd then bundle multiple domain messages into a single RMQ-message and .produce() it to RMQ. Remember this kind of design introduces timeouts and latencies due to the existence of a window (you might take some impression from Kafka that does bundling to optimize I/O at the cost of latency).
As a consumer then, you'd have a consumer, with typical .handleDelivery implementation that would transform the received body for the processing: byte[] -> Set[DomainMessage] -> your listener.

Difference between Pending Messages and Enqueue Counter in Active MQ?

In the Active MQ Admin console of what is the difference between "Number Of Pending Messages" and "Messages Enqueued"? When a Message is placed on to the queue, should both these values should match?
pending messages = number of messages CURRENTLY waiting for delivery in the destination (the current size of the queue)
enqueued messages = number of messages that where enqueued in the destination since the last statistic reset. This number can only rise.
dequeued messages = messages delivered from the destination to consumers. this number can be higher that the number of enqueued messages if a message was delivered to multiple consumers (topics).
Messages Enqueued = Number of messages sent to the queue since the server start
Messages Dequeued = Number of messages received+deleted since the server start