Java Code Examples for javax.jms.JMSConsumer#receiveNoWait()

The following examples show how to use javax.jms.JMSConsumer#receiveNoWait() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsPoolJMSConsumerTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testReceiveNoWait() throws JMSException {
    JMSConsumer consumer = context.createConsumer(context.createTemporaryQueue());

    assertNull(consumer.receiveNoWait());

    consumer.close();

    try {
        consumer.receiveNoWait();
        fail("Should not be able to interact with closed consumer");
    } catch (IllegalStateRuntimeException ise) {}
}
 
Example 2
Source File: JMSConsumerIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=20000)
public void testConsumerReceiveNoWaitThrowsIfConnectionLost() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JMSContext context = testFixture.createJMSContext(testPeer);

        testPeer.expectBegin();

        Queue queue = context.createQueue("queue");

        testPeer.expectReceiverAttach();
        testPeer.expectLinkFlow(false, notNullValue(UnsignedInteger.class));
        testPeer.expectLinkFlow(true, notNullValue(UnsignedInteger.class));
        testPeer.dropAfterLastHandler();

        final JMSConsumer consumer = context.createConsumer(queue);

        try {
            consumer.receiveNoWait();
            fail("An exception should have been thrown");
        } catch (JMSRuntimeException jmsre) {
            // Expected
        }

        try {
            context.close();
        } catch (Throwable ignored) {
        }
    }
}
 
Example 3
Source File: JmsContextTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testReceiveBytes() throws Exception {
   JMSProducer producer = context.createProducer();

   JMSConsumer consumer = context.createConsumer(queue1);

   BytesMessage bytesSend = context.createBytesMessage();
   bytesSend.writeByte((byte) 1);
   bytesSend.writeLong(2L);
   producer.send(queue1, bytesSend);

   BytesMessage msgReceived = (BytesMessage) consumer.receiveNoWait();

   byte[] bytesArray = msgReceived.getBody(byte[].class);

   assertEquals((byte) 1, msgReceived.readByte());
   assertEquals(2L, msgReceived.readLong());

   DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytesArray));

   assertEquals((byte) 1, dataInputStream.readByte());
   assertEquals(2L, dataInputStream.readLong());

}
 
Example 4
Source File: JmsContextTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testReceiveText() throws Exception {
   JMSProducer producer = context.createProducer();

   JMSConsumer consumer = context.createConsumer(queue1);

   String randomStr = newXID().toString();

   TextMessage sendMsg = context.createTextMessage(randomStr);
   producer.send(queue1, sendMsg);

   TextMessage receiveMsg = (TextMessage) consumer.receiveNoWait();

   assertEquals(randomStr, receiveMsg.getText());

}
 
Example 5
Source File: JmsContextTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeliveryMode() throws Exception {
   JMSProducer producer = context.createProducer();

   JMSConsumer consumer = context.createConsumer(queue1);

   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   String strRandom = newXID().toString();

   producer.send(queue1, context.createTextMessage(strRandom));

   TextMessage msg = (TextMessage) consumer.receiveNoWait();

   assertNotNull(msg);

   assertEquals(DeliveryMode.NON_PERSISTENT, msg.getJMSDeliveryMode());

}