[
https://issues.apache.org/jira/browse/ARTEMIS-2417?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16881224#comment-16881224
]
Hans Drexler commented on ARTEMIS-2417:
---------------------------------------
We have the same problem. We created a sample program based on
DelayedRedeliveryExample from the examples in the distribution. This
modification:
# Sends a single message with text: "ROLLBACK"
# Sends 10 messages with a message number 1..10
# Receives and rollbacks the first message ("ROLLBACK")
# Loops listening until 11 messages Received (every time listening for 1
second)
*expected*
We would expect the numbered text messages 1..10 to be received immediately,
and the ROLLBACK message last, after waiting 5 seconds.
*actual*
The program waits until the ROLLBACK message is redelivered, and receives the
numbered text messages after that.
{code:java}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.jms.example;
import java.util.stream.IntStream;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
/**
* This example demonstrates how ActiveMQ Artemis can be configured with a
redelivery delay in the event a message is
* redelivered.
*
* Please see the readme for more information
*/
public class DelayedRedeliveryExample {
public static void main(final String[] args) throws Exception {
Connection connection = null;
InitialContext initialContext = null;
try {
// Step 1. Create an initial context to perform the JNDI lookup.
initialContext = new InitialContext();
// Step 2. Perform a lookup on the queue
Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
// Step 3. Perform a lookup on the Connection Factory
ConnectionFactory cf = (ConnectionFactory)
initialContext.lookup("ConnectionFactory");
// Step 4. Create a JMS Connection
connection = cf.createConnection();
// Step 5. Create a transacted JMS Session
Session session = connection.createSession(true, 0);
// Step 6. Create a JMS Message Producer
MessageProducer producer = session.createProducer(queue);
// Step 7. Create a Text Message
TextMessage message = session.createTextMessage("ROLLBACK");
// Step 8. Send the Message
producer.send(message);
// Step 9. Commit the session to effectively send the message
session.commit();
System.out.println("Sent message to " + queue.getQueueName() + ": "
+ message.getText());
// Step 9a. Construct and send some more messages.
IntStream.range(1, 11).forEach(i -> {
try {
TextMessage m2 = session.createTextMessage("Text message
no." + i);
producer.send(m2);
session.commit();
System.out.println("Sent message to " +
queue.getQueueName() + ": " + m2.getText());
} catch (JMSException e) {
}
});
// Step 9b. Commit the session to effectively send the messages
session.commit();
// Step 10. Create a JMS Message Consumer for the queue
MessageConsumer messageConsumer = session.createConsumer(queue);
// Step 11. Start the Connection
connection.start();
// Step 12. We receive a message...
TextMessage messageReceived = (TextMessage)
messageConsumer.receive(5000);
String text = messageReceived.getText();
System.out.println("1st delivery from " + queue.getQueueName() + ":
" + text);
// Step 13. ... but we roll back the session. the message returns
to the queue, but only after a
// 5 second delay
if (text.contains("ROLLBACK")) {
System.out.println("Message rolled back");
session.rollback();
} else {
throw new IllegalStateException("Expected the ROLLBACK message
first.");
}
// Step 14. We try to receive the message but it's being delayed
int messageCount = 0;
while (messageCount < 11) {
messageReceived = (TextMessage) messageConsumer.receive(1000);
while (messageReceived == null) {
System.out.println("waited 1 second...");
messageReceived = (TextMessage)
messageConsumer.receive(1000);
}
messageCount += 1;
System.out.println("Received message # " + messageCount + ": "
+ messageReceived.getText());
}
} finally {
// Step 17. Be sure to close our JMS resources!
if (initialContext != null) {
initialContext.close();
}
if (connection != null) {
connection.close();
}
}
}
}
{code}
This code produces the following output:
{noformat}
Sent message to exampleQueue: ROLLBACK
Sent message to exampleQueue: Text message no.1
Sent message to exampleQueue: Text message no.2
Sent message to exampleQueue: Text message no.3
Sent message to exampleQueue: Text message no.4
Sent message to exampleQueue: Text message no.5
Sent message to exampleQueue: Text message no.6
Sent message to exampleQueue: Text message no.7
Sent message to exampleQueue: Text message no.8
Sent message to exampleQueue: Text message no.9
Sent message to exampleQueue: Text message no.10
1st delivery from exampleQueue: ROLLBACK
Message rolled back
waited 1 second...
waited 1 second...
waited 1 second...
waited 1 second...
Received message # 1: ROLLBACK
Received message # 2: Text message no.1
Received message # 3: Text message no.2
Received message # 4: Text message no.3
Received message # 5: Text message no.4
Received message # 6: Text message no.5
Received message # 7: Text message no.6
Received message # 8: Text message no.7
Received message # 9: Text message no.8
Received message # 10: Text message no.9
Received message # 11: Text message no.10{noformat}
As you can see, after the first message is rolled back, no messages are
delivered until it is redelivered.
We would expect the text messages 1 through 10 to be delivered without waiting
for the redelivery of the first message.
> Broker redelivery policy delays all messages currently on queue
> ---------------------------------------------------------------
>
> Key: ARTEMIS-2417
> URL: https://issues.apache.org/jira/browse/ARTEMIS-2417
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Components: Broker
> Affects Versions: 2.9.0
> Environment: I have been running Artemis on a docker container based
> on:
> FROM openjdk:8-jre-alpine
> Reporter: Ben Thurley
> Priority: Major
>
> *Steps to recreate:*
> # Create a queue with the following settings in broker.xml
> # Publish several messages to the queue without a delay between messages
> (I'm using JmsTemplate in spring and CORE)
> # Have a consumer consume the messages and throw an exception to allow the
> redelivery policy to take affect
> <address-settings>
> <address-setting match="jms.queue.TestQueue">
> <dead-letter-address>DLQ</dead-letter-address>
> <redelivery-delay>10000</redelivery-delay>
> <max-delivery-attempts>3</max-delivery-attempts>
> </address-setting>
> </address-settings>
> <addresses>
> <address name="DLQ">
> <anycast>
> <queue name="DLQ" />
> </anycast>
> </address>
> <address name="jms.queue.TestQueue">
> <anycast>
> <queue name="jms.queue.TestQueue" />
> </anycast>
> </address>
> </addresses>
>
> *Expected behaviour:*
> The documentation says the following:
> "Other subsequent messages will be delivery regularly, only the cancelled
> message will be sent asynchronously back to the queue after the delay."
> So I was expecting the failed message to go back as a scheduled message with
> a delay and the remaining messages to be attempted to be delivered as normal.
> This was also how things worked on AMQ 5.*.
>
> *Actual behaviour:*
> In reality all of the messages arrive back on the queue as scheduled messages
> with whatever redelivery-delay is configured.
> If the messages are sent to the queue with a bit of a delay between them then
> it can work out that only the failed message is rescheduled with the delay.
> It's only the messages that happen to be on the queue when one fails that all
> get sent back and rescheduled.
> The first message that causes the failure (and redelivery) has it's delivery
> count incremented, the other messages weren't actually delivered and their
> delivery count is not incremented.
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)