-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARTEMIS-5093 support configurable onMessage timeout w/closing consumer #5291
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1298,6 +1298,18 @@ public ServerLocatorImpl setInitialMessagePacketSize(final int size) { | |
return this; | ||
} | ||
|
||
@Override | ||
public int getOnMessageCloseTimeout() { | ||
return config.onMessageCloseTimeout; | ||
} | ||
|
||
@Override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API docs specify the value set must be greater than zero, but there isn't any validation of that, should there be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm...That comment was left-over from a copy & paste. I went looking through the existing code to see how validation is done for other parameters, and I'm not actually seeing any. I'm continuing my investigation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did look into what it does with that configuration value and since it is passing into a CountdownLatch is seems like it will not trigger an exception but will return immediately so from the standpoint of being able to be set to zero or negative it works, although seems an absurd value to assign. |
||
public ServerLocator setOnMessageCloseTimeout(int onMessageCloseTimeout) { | ||
checkWrite(); | ||
config.onMessageCloseTimeout = onMessageCloseTimeout; | ||
return this; | ||
} | ||
|
||
@Override | ||
public ServerLocatorImpl setGroupID(final String groupID) { | ||
checkWrite(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,16 +16,12 @@ | |
*/ | ||
package org.apache.activemq.artemis.tests.integration.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.activemq.artemis.api.core.QueueConfiguration; | ||
import org.apache.activemq.artemis.api.core.SimpleString; | ||
import org.apache.activemq.artemis.api.core.client.ActiveMQClient; | ||
import org.apache.activemq.artemis.api.core.client.ClientConsumer; | ||
import org.apache.activemq.artemis.api.core.client.ClientMessage; | ||
import org.apache.activemq.artemis.api.core.client.ClientProducer; | ||
|
@@ -38,6 +34,11 @@ | |
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class MessageHandlerTest extends ActiveMQTestBase { | ||
|
||
private ActiveMQServer server; | ||
|
@@ -117,6 +118,42 @@ public void onMessage(final ClientMessage message) { | |
session.close(); | ||
} | ||
|
||
@Test | ||
public void testMessageHandlerCloseTimeout() throws Exception { | ||
// create Netty acceptor so client can use new onMessageCloseTimeout URL parameter | ||
server.getRemotingService().createAcceptor("netty", "tcp://127.0.0.1:61616").start(); | ||
final int timeout = 1000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the test work with a lower timeout to reduce the test duration? |
||
locator = ActiveMQClient.createServerLocator("tcp://127.0.0.1:61616?onMessageCloseTimeout=" + timeout); | ||
sf = createSessionFactory(locator); | ||
ClientSession session = addClientSession(sf.createSession(false, true, true)); | ||
session.createQueue(QueueConfiguration.of(QUEUE).setDurable(false)); | ||
ClientProducer producer = session.createProducer(QUEUE); | ||
producer.send(createTextMessage(session, "m")); | ||
|
||
ClientConsumer consumer = session.createConsumer(QUEUE, null, false); | ||
|
||
session.start(); | ||
|
||
CountDownLatch latch = new CountDownLatch(1); | ||
consumer.setMessageHandler(message -> { | ||
latch.countDown(); | ||
// don't just Thread.sleep() here because it will be interrupted on ClientConsumer.close() | ||
long start = System.currentTimeMillis(); | ||
while (System.currentTimeMillis() - start < 2000) { | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException e) { | ||
// ignore | ||
} | ||
} | ||
}); | ||
latch.await(); | ||
long start = System.currentTimeMillis(); | ||
consumer.close(); | ||
long end = System.currentTimeMillis(); | ||
assertTrue( (end - start >= timeout) && (end - start <= 2000), "Closing consumer took " + (end - start) + "ms"); | ||
} | ||
|
||
@Test | ||
public void testSetResetMessageHandler() throws Exception { | ||
final ClientSession session = sf.createSession(false, true, true); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the const
CLOSE_TIMEOUT_MILLISECONDS
still required?