Search in sources :

Example 1 with JmsConnection

use of org.apache.qpid.jms.JmsConnection in project activemq-artemis by apache.

the class JMSMessageConsumerTest method testZeroPrefetchWithTwoConsumers.

@Test(timeout = 60000)
public void testZeroPrefetchWithTwoConsumers() throws Exception {
    JmsConnection connection = (JmsConnection) createConnection();
    ((JmsDefaultPrefetchPolicy) connection.getPrefetchPolicy()).setAll(0);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Queue queue = session.createQueue(getQueueName());
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Msg1"));
    producer.send(session.createTextMessage("Msg2"));
    // now lets receive it
    MessageConsumer consumer1 = session.createConsumer(queue);
    MessageConsumer consumer2 = session.createConsumer(queue);
    TextMessage answer = (TextMessage) consumer1.receive(5000);
    assertNotNull(answer);
    assertEquals("Should have received a message!", answer.getText(), "Msg1");
    answer = (TextMessage) consumer2.receive(5000);
    assertNotNull(answer);
    assertEquals("Should have received a message!", answer.getText(), "Msg2");
    answer = (TextMessage) consumer2.receiveNoWait();
    assertNull("Should have not received a message!", answer);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JmsDefaultPrefetchPolicy(org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy) JmsConnection(org.apache.qpid.jms.JmsConnection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with JmsConnection

use of org.apache.qpid.jms.JmsConnection in project activemq-artemis by apache.

the class JMSMessageConsumerTest method doTestProduceAndConsumeLargeNumbersOfMessages.

public void doTestProduceAndConsumeLargeNumbersOfMessages(boolean topic, int ackMode) throws Exception {
    final int MSG_COUNT = 1000;
    final CountDownLatch done = new CountDownLatch(MSG_COUNT);
    JmsConnection connection = (JmsConnection) createConnection();
    connection.setForceAsyncSend(true);
    connection.start();
    Session session = connection.createSession(false, ackMode);
    final Destination destination;
    if (topic) {
        destination = session.createTopic(getTopicName());
    } else {
        destination = session.createQueue(getQueueName());
    }
    MessageConsumer consumer = session.createConsumer(destination);
    consumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                message.acknowledge();
                done.countDown();
            } catch (JMSException ex) {
                LOG.info("Caught exception.", ex);
            }
        }
    });
    MessageProducer producer = session.createProducer(destination);
    TextMessage textMessage = session.createTextMessage();
    textMessage.setText("messageText");
    for (int i = 0; i < MSG_COUNT; i++) {
        producer.send(textMessage);
    }
    assertTrue("Did not receive all messages: " + MSG_COUNT, done.await(15, TimeUnit.SECONDS));
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) JmsConnection(org.apache.qpid.jms.JmsConnection) MessageProducer(javax.jms.MessageProducer) CountDownLatch(java.util.concurrent.CountDownLatch) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 3 with JmsConnection

use of org.apache.qpid.jms.JmsConnection in project activemq-artemis by apache.

the class JMSQueueBrowserTest method testBrowseAllInQueueZeroPrefetch.

@Test(timeout = 60000)
public void testBrowseAllInQueueZeroPrefetch() throws Exception {
    final int MSG_COUNT = 5;
    JmsConnection connection = (JmsConnection) createConnection();
    ((JmsDefaultPrefetchPolicy) connection.getPrefetchPolicy()).setAll(0);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    javax.jms.Queue queue = session.createQueue(getQueueName());
    sendMessages(name.getMethodName(), MSG_COUNT, false);
    Queue queueView = getProxyToQueue(getQueueName());
    Wait.assertEquals(MSG_COUNT, queueView::getMessageCount);
    QueueBrowser browser = session.createBrowser(queue);
    assertNotNull(browser);
    Enumeration<?> enumeration = browser.getEnumeration();
    int count = 0;
    while (count < MSG_COUNT && enumeration.hasMoreElements()) {
        Message msg = (Message) enumeration.nextElement();
        assertNotNull(msg);
        LOG.debug("Recv: {}", msg);
        count++;
    }
    LOG.debug("Received all expected message, checking that hasMoreElements returns false");
    assertFalse(enumeration.hasMoreElements());
    assertEquals(5, count);
}
Also used : JmsDefaultPrefetchPolicy(org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(org.apache.activemq.artemis.core.server.Queue) QueueBrowser(javax.jms.QueueBrowser) Session(javax.jms.Session) Test(org.junit.Test)

Example 4 with JmsConnection

use of org.apache.qpid.jms.JmsConnection in project activemq-artemis by apache.

the class JMSWebSocketConnectionTest method testSendLargeMessageToClientFromOpenWire.

@Test(timeout = 30000)
public void testSendLargeMessageToClientFromOpenWire() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JmsConnection connection = (JmsConnection) factory.createConnection();
    sendLargeMessageViaOpenWire();
    try {
        Session session = connection.createSession();
        Queue queue = session.createQueue(getQueueName());
        connection.start();
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(1000);
        assertNotNull(message);
        assertTrue(message instanceof BytesMessage);
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) BytesMessage(javax.jms.BytesMessage) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 5 with JmsConnection

use of org.apache.qpid.jms.JmsConnection in project activemq-artemis by apache.

the class JMSWebSocketConnectionTest method testCreateConnectionAndStart.

@Test(timeout = 30000)
public void testCreateConnectionAndStart() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JmsConnection connection = (JmsConnection) factory.createConnection();
    assertNotNull(connection);
    connection.start();
    connection.close();
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) JmsConnection(org.apache.qpid.jms.JmsConnection) Test(org.junit.Test)

Aggregations

JmsConnection (org.apache.qpid.jms.JmsConnection)7 Session (javax.jms.Session)6 Test (org.junit.Test)6 Message (javax.jms.Message)5 MessageConsumer (javax.jms.MessageConsumer)5 BytesMessage (javax.jms.BytesMessage)4 JmsConnectionFactory (org.apache.qpid.jms.JmsConnectionFactory)4 MessageProducer (javax.jms.MessageProducer)3 Queue (javax.jms.Queue)3 TextMessage (javax.jms.TextMessage)3 JmsDefaultPrefetchPolicy (org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Destination (javax.jms.Destination)1 JMSException (javax.jms.JMSException)1 MessageListener (javax.jms.MessageListener)1 QueueBrowser (javax.jms.QueueBrowser)1 Queue (org.apache.activemq.artemis.core.server.Queue)1 Ignore (org.junit.Ignore)1