use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AMQPToOpenwireTest method testDeliveryCountMessage.
@Test
public void testDeliveryCountMessage() throws Exception {
AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
AmqpConnection amqpconnection = client.connect();
try {
AmqpSession session = amqpconnection.createSession();
AmqpSender sender = session.createSender(queueName);
AmqpMessage message = new AmqpMessage();
message.setMessageId("MessageID:" + 0);
message.getWrappedMessage().setHeader(new Header());
message.getWrappedMessage().getHeader().setDeliveryCount(new UnsignedInteger(2));
sender.send(message);
} finally {
amqpconnection.close();
}
Connection connection = null;
try {
connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(queueName);
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
Message receive = consumer.receive(5000);
assertNotNull(receive);
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AMQPToJMSCoreTest method testMessageDestination.
@Test
public void testMessageDestination() throws Exception {
System.out.println("foo");
AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
AmqpConnection amqpconnection = client.connect();
try {
AmqpSession session = amqpconnection.createSession();
AmqpSender sender = session.createSender(queueName);
AmqpMessage message = new AmqpMessage();
message.setMessageId("MessageID:" + 0);
// message.setApplicationProperty("_AMQ_ROUTING_TYPE", (byte) 1);
message.getWrappedMessage().setHeader(new Header());
message.getWrappedMessage().getHeader().setDeliveryCount(new UnsignedInteger(2));
sender.send(message);
} finally {
amqpconnection.close();
}
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
Connection connection = null;
try {
connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queueName));
connection.start();
Message message = consumer.receive(2000);
Assert.assertNotNull(message);
ActiveMQDestination jmsDestination = (ActiveMQDestination) message.getJMSDestination();
Assert.assertEquals(queueName, jmsDestination.getAddress());
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AMQPToStompTest method testSendAmqpReceiveStomp.
@Test
public void testSendAmqpReceiveStomp() throws Exception {
AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
AmqpConnection amqpconnection = client.connect();
try {
AmqpSession session = amqpconnection.createSession();
AmqpSender sender = session.createSender(queueName);
AmqpMessage message = new AmqpMessage();
message.setText("mine");
sender.send(message);
} finally {
amqpconnection.close();
}
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(new URI("tcp://127.0.0.1:61616"));
conn.connect(null, null);
try {
StompTestBase.subscribeQueue(conn, null, queueName);
ClientStompFrame frame = conn.receiveFrame();
assertNotNull(frame);
assertNotNull(frame.getBody());
assertTrue(frame.getBody().contains("mine"));
} finally {
conn.closeTransport();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class MQTTTest method testLinkRouteAmqpReceiveMQTT.
@Test(timeout = 60 * 1000)
public void testLinkRouteAmqpReceiveMQTT() throws Exception {
MQTT mqtt = createMQTTConnection();
mqtt.setClientId("TestClient");
BlockingConnection blockingConnection = mqtt.blockingConnection();
blockingConnection.connect();
Topic t = new Topic("test", QoS.AT_LEAST_ONCE);
blockingConnection.subscribe(new Topic[] { t });
AmqpClient client = new AmqpClient(new URI(AMQP_URI), null, null);
AmqpConnection connection = client.connect();
try {
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender("test", true);
AmqpMessage message = new AmqpMessage();
message.setText("Test-Message");
sender.send(message);
sender.close();
} finally {
connection.close();
}
try {
blockingConnection.subscribe(new Topic[] { t });
assertNotNull(blockingConnection.receive(5, TimeUnit.SECONDS));
} finally {
blockingConnection.kill();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AmqpSecurityTest method testSendMessageFailsOnAnonymousRelayWhenNotAuthorizedToSendToAddress.
@Test(timeout = 60000)
public void testSendMessageFailsOnAnonymousRelayWhenNotAuthorizedToSendToAddress() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AmqpClient client = createAmqpClient(guestUser, guestPass);
client.setValidator(new AmqpValidator() {
@Override
public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
DeliveryState state = delivery.getRemoteState();
if (!delivery.remotelySettled()) {
markAsInvalid("delivery is not remotely settled");
}
if (state instanceof Rejected) {
Rejected rejected = (Rejected) state;
if (rejected.getError() == null || rejected.getError().getCondition() == null) {
markAsInvalid("Delivery should have been Rejected with an error condition");
} else {
ErrorCondition error = rejected.getError();
if (!error.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
markAsInvalid("Should have been tagged with unauthorized access error");
}
}
} else {
markAsInvalid("Delivery should have been Rejected");
}
latch.countDown();
}
});
AmqpConnection connection = 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");
try {
sender.send(message);
fail("Should not be able to send, message should be rejected");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
sender.close();
}
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
connection.getStateInspector().assertValid();
} finally {
connection.close();
}
}
Aggregations