Search in sources :

Example 66 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpSendReceiveTest method testMessageDurabliltyFollowsSpec.

@Test(timeout = 60000)
public void testMessageDurabliltyFollowsSpec() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    AmqpReceiver receiver1 = session.createReceiver(getQueueName());
    Queue queue = getProxyToQueue(getQueueName());
    // Create default message that should be sent as non-durable
    AmqpMessage message1 = new AmqpMessage();
    message1.setText("Test-Message -> non-durable");
    message1.setDurable(false);
    message1.setMessageId("ID:Message:1");
    sender.send(message1);
    Wait.assertEquals(1, queue::getMessageCount);
    receiver1.flow(1);
    message1 = receiver1.receive(50, TimeUnit.SECONDS);
    assertNotNull("Should have read a message", message1);
    assertFalse("First message sent should not be durable", message1.isDurable());
    message1.accept();
    // Create default message that should be sent as durable
    AmqpMessage message2 = new AmqpMessage();
    message2.setText("Test-Message -> durable");
    message2.setDurable(true);
    message2.setMessageId("ID:Message:2");
    sender.send(message2);
    Wait.assertEquals(1, queue::getMessageCount);
    receiver1.flow(1);
    message2 = receiver1.receive(50, TimeUnit.SECONDS);
    assertNotNull("Should have read a message", message2);
    assertTrue("Second message sent should be durable", message2.isDurable());
    message2.accept();
    sender.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 67 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpSendReceiveTest method testCoreBridge.

@Test(timeout = 60000)
public void testCoreBridge() throws Exception {
    server.getRemotingService().createAcceptor("acceptor", "vm://0").start();
    server.getConfiguration().addConnectorConfiguration("connector", "vm://0");
    server.deployBridge(new BridgeConfiguration().setName(getTestName()).setQueueName(getQueueName()).setForwardingAddress(getQueueName(1)).setConfirmationWindowSize(10).setStaticConnectors(Arrays.asList("connector")));
    sendMessages(getQueueName(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(getQueueName(1));
    Queue queueView = getProxyToQueue(getQueueName());
    Wait.assertEquals(1, queueView::getConsumerCount);
    Wait.assertEquals(0, queueView::getMessageCount);
    queueView = getProxyToQueue(getQueueName(1));
    Wait.assertEquals(1, queueView::getConsumerCount);
    Wait.assertEquals(1, queueView::getMessageCount);
    receiver.flow(1);
    AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    message.accept();
    receiver.close();
    Wait.assertEquals(0, queueView::getMessageCount);
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 68 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpSendReceiveTest method testReceiveWithJMSSelectorFilterOnJMSType.

@Test(timeout = 60000)
public void testReceiveWithJMSSelectorFilterOnJMSType() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpMessage message1 = new AmqpMessage();
    message1.setText("msg:1");
    AmqpMessage message2 = new AmqpMessage();
    message2.setSubject("target");
    message2.setText("msg:2");
    AmqpSender sender = session.createSender(getQueueName());
    sender.send(message1);
    sender.send(message2);
    sender.close();
    AmqpReceiver receiver = session.createReceiver(getQueueName(), "JMSType = 'target'");
    receiver.flow(2);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull("Should have read a message", received);
    assertEquals("target", received.getSubject());
    received.accept();
    assertNull(receiver.receive(1, TimeUnit.SECONDS));
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 69 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpSendReceiveTest method testDispatchOrderWithPrefetchOfOne.

@Test(timeout = 60000)
public void testDispatchOrderWithPrefetchOfOne() throws Exception {
    final int MSG_COUNT = 20;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    for (int i = 0; i < MSG_COUNT; i++) {
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("msg" + i);
        message.setMessageAnnotation("serialNo", i);
        message.setText("Test-Message");
        sender.send(message);
    }
    sender.close();
    AmqpReceiver receiver1 = session.createReceiver(getQueueName());
    receiver1.flow(1);
    AmqpReceiver receiver2 = session.createReceiver(getQueueName());
    receiver2.flow(1);
    AmqpMessage message1 = receiver1.receive(10, TimeUnit.SECONDS);
    AmqpMessage message2 = receiver2.receive(10, TimeUnit.SECONDS);
    assertNotNull("Should have read message 1", message1);
    assertNotNull("Should have read message 2", message2);
    assertEquals("msg0", message1.getMessageId());
    assertEquals("msg1", message2.getMessageId());
    message1.accept();
    message2.accept();
    receiver1.flow(1);
    AmqpMessage message3 = receiver1.receive(10, TimeUnit.SECONDS);
    receiver2.flow(1);
    AmqpMessage message4 = receiver2.receive(10, TimeUnit.SECONDS);
    assertNotNull("Should have read message 3", message3);
    assertNotNull("Should have read message 4", message4);
    assertEquals("msg2", message3.getMessageId());
    assertEquals("msg3", message4.getMessageId());
    message3.accept();
    message4.accept();
    LOG.info("*** Attempting to read remaining messages with both receivers");
    int splitCredit = (MSG_COUNT - 4) / 2;
    LOG.info("**** Receiver #1 granting credit[{}] for its block of messages", splitCredit);
    receiver1.flow(splitCredit);
    for (int i = 0; i < splitCredit; i++) {
        AmqpMessage message = receiver1.receive(10, TimeUnit.SECONDS);
        assertNotNull("Receiver #1 should have read a message", message);
        LOG.info("Receiver #1 read message: {}", message.getMessageId());
        message.accept();
    }
    LOG.info("**** Receiver #2 granting credit[{}] for its block of messages", splitCredit);
    receiver2.flow(splitCredit);
    for (int i = 0; i < splitCredit; i++) {
        AmqpMessage message = receiver2.receive(10, TimeUnit.SECONDS);
        assertNotNull("Receiver #2 should have read message[" + i + "]", message);
        LOG.info("Receiver #2 read message: {}", message.getMessageId());
        message.accept();
    }
    receiver1.close();
    receiver2.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 70 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpSendReceiveTest method testTwoPresettledReceiversReceiveAllMessages.

@Test(timeout = 60000)
public void testTwoPresettledReceiversReceiveAllMessages() throws Exception {
    final int MSG_COUNT = 100;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final String address = getQueueName();
    AmqpSender sender = session.createSender(address);
    AmqpReceiver receiver1 = session.createReceiver(address, null, false, true);
    AmqpReceiver receiver2 = session.createReceiver(address, null, false, true);
    for (int i = 0; i < MSG_COUNT; i++) {
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("msg" + i);
        sender.send(message);
    }
    LOG.info("Attempting to read first two messages with receiver #1");
    receiver1.flow(2);
    AmqpMessage message1 = receiver1.receive(10, TimeUnit.SECONDS);
    AmqpMessage message2 = receiver1.receive(10, TimeUnit.SECONDS);
    assertNotNull("Should have read message 1", message1);
    assertNotNull("Should have read message 2", message2);
    assertEquals("msg0", message1.getMessageId());
    assertEquals("msg1", message2.getMessageId());
    message1.accept();
    message2.accept();
    LOG.info("Attempting to read next two messages with receiver #2");
    receiver2.flow(2);
    AmqpMessage message3 = receiver2.receive(10, TimeUnit.SECONDS);
    AmqpMessage message4 = receiver2.receive(10, TimeUnit.SECONDS);
    assertNotNull("Should have read message 3", message3);
    assertNotNull("Should have read message 4", message4);
    assertEquals("msg2", message3.getMessageId());
    assertEquals("msg3", message4.getMessageId());
    message3.accept();
    message4.accept();
    LOG.info("*** Attempting to read remaining messages with both receivers");
    int splitCredit = (MSG_COUNT - 4) / 2;
    LOG.info("**** Receiver #1 granting credit[{}] for its block of messages", splitCredit);
    receiver1.flow(splitCredit);
    for (int i = 0; i < splitCredit; i++) {
        AmqpMessage message = receiver1.receive(10, TimeUnit.SECONDS);
        assertNotNull("Receiver #1 should have read a message", message);
        LOG.info("Receiver #1 read message: {}", message.getMessageId());
        message.accept();
    }
    LOG.info("**** Receiver #2 granting credit[{}] for its block of messages", splitCredit);
    receiver2.flow(splitCredit);
    for (int i = 0; i < splitCredit; i++) {
        AmqpMessage message = receiver2.receive(10, TimeUnit.SECONDS);
        assertNotNull("Receiver #2 should have read a message[" + i + "]", message);
        LOG.info("Receiver #2 read message: {}", message.getMessageId());
        message.accept();
    }
    receiver1.close();
    receiver2.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Aggregations

AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)118 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)115 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)114 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)114 Test (org.junit.Test)100 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)94 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)82 Queue (org.apache.activemq.artemis.core.server.Queue)56 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)16 Source (org.apache.qpid.proton.amqp.messaging.Source)9 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Connection (javax.jms.Connection)4 Message (javax.jms.Message)4 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)4 Delivery (org.apache.qpid.proton.engine.Delivery)4