use of org.apache.activemq.transport.amqp.client.AmqpSession 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();
}
use of org.apache.activemq.transport.amqp.client.AmqpSession 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();
}
use of org.apache.activemq.transport.amqp.client.AmqpSession 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();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSession 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();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSession 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();
}
}
Aggregations