You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Robbie Gemmell (Jira)" <ji...@apache.org> on 2019/10/14 13:39:00 UTC

[jira] [Commented] (ARTEMIS-2520) Consumer.receive return null if server is stopped

    [ https://issues.apache.org/jira/browse/ARTEMIS-2520?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16951004#comment-16951004 ] 

Robbie Gemmell commented on ARTEMIS-2520:
-----------------------------------------

Returning null in this case is often whats done since the spec says receive should return null if the consumer is concurrently closed, and also that problems sent to the connection ExceptionListener (which connection failure typically is) should generally not be thrown to a specific method call (since its going to the listener). Any further calls to receive would be expected to throw since the consumer is closed.

> Consumer.receive return null if server is stopped
> -------------------------------------------------
>
>                 Key: ARTEMIS-2520
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-2520
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>            Reporter: Domenico Bruscino
>            Priority: Major
>
> ActiveMQMessageConsumer.receive(timeout) returns null, if the server is stopped during the call.
> Test to reproduce:
> {code:java}
> ConnectionFactory factorySend = new ActiveMQConnectionFactory();
> Connection connection = factorySend.createConnection();
> try (Session session = connection.createSession()) {
>    javax.jms.Queue queue = session.createQueue("queueStop");
>    MessageProducer producer = session.createProducer(queue);
>    producer.send(session.createTextMessage("text"));
>    connection.start();
>    MessageConsumer consumer = session.createConsumer(queue);
>    assertNotNull(consumer.receive(1000));
>    final CountDownLatch stoppingLatch = new CountDownLatch(1);
>    (new Thread(new Runnable() {
>       @Override
>       public void run() {
>          try {
>             stoppingLatch.countDown();
>             Thread.sleep(1000);
>             server.stop();
>          } catch (Exception e) {
>             e.printStackTrace();
>          }
>       }
>    })).start();
>    try {
>       stoppingLatch.await();
>       consumer.receive(5000);
>       Assert.fail("didn't get expected exception!");
>    } catch (Exception e) {
>       e.printStackTrace();
>    }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)