Search in sources :

Example 41 with AmqpMessage

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

the class AmqpMessagePriorityTest method testMessageDefaultPriority.

@Test(timeout = 60000)
public void testMessageDefaultPriority() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("MessageID:1");
    message.setPriority((short) 4);
    sender.send(message);
    sender.close();
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(1, queueView.getMessageCount());
    receiver.flow(1);
    AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(receive);
    assertEquals((short) 4, receive.getPriority());
    receiver.close();
    assertEquals(1, 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) 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 42 with AmqpMessage

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

the class AmqpMessagePriorityTest method testMessagePriorityOrdering.

@Test(timeout = 60000)
public void testMessagePriorityOrdering() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    for (short i = 0; i <= 9; ++i) {
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("MessageID:" + i);
        message.setPriority(i);
        sender.send(message);
    }
    sender.close();
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(10, queueView.getMessageCount());
    receiver.flow(10);
    for (int i = 9; i >= 0; --i) {
        AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
        assertNotNull(received);
        assertEquals((short) i, received.getPriority());
        received.accept();
    }
    receiver.close();
    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) 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 43 with AmqpMessage

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

the class AmqpAnonymousRelayTest method testSendMessageFailsOnAnonymousRelayWhenToFieldHasNonExistingAddress.

@Test(timeout = 60000)
public void testSendMessageFailsOnAnonymousRelayWhenToFieldHasNonExistingAddress() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createAnonymousSender();
        AmqpMessage message = new AmqpMessage();
        message.setAddress("exampleQueu-not-in-service");
        message.setMessageId("msg" + 1);
        message.setText("Test-Message");
        try {
            sender.send(message);
            fail("Should not be able to send, message should be rejected");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            sender.close();
        }
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) 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 44 with AmqpMessage

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

the class AmqpAnonymousRelayTest method testSendMessageOnAnonymousRelayLinkUsingMessageTo.

@Test(timeout = 60000)
public void testSendMessageOnAnonymousRelayLinkUsingMessageTo() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createAnonymousSender();
        AmqpMessage message = new AmqpMessage();
        message.setAddress(getQueueName());
        message.setMessageId("msg" + 1);
        message.setText("Test-Message");
        sender.send(message);
        sender.close();
        AmqpReceiver receiver = session.createReceiver(getQueueName());
        receiver.flow(1);
        AmqpMessage received = receiver.receive(10, TimeUnit.SECONDS);
        assertNotNull("Should have read message", received);
        assertEquals("msg1", received.getMessageId());
        received.accept();
        receiver.close();
    } finally {
        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 45 with AmqpMessage

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

the class AmqpAnonymousRelayTest method testSendMessageFailsOnAnonymousRelayLinkWhenNoToValueSet.

@Test(timeout = 60000)
public void testSendMessageFailsOnAnonymousRelayLinkWhenNoToValueSet() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createAnonymousSender();
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("msg" + 1);
        message.setText("Test-Message");
        try {
            sender.send(message);
            fail("Should not be able to send, message should be rejected");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            sender.close();
        }
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) 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)

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