Search in sources :

Example 1 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage 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();
        }
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) BytesMessage(javax.jms.BytesMessage) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(javax.jms.Connection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Header(org.apache.qpid.proton.amqp.messaging.Header) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) Queue(javax.jms.Queue) Session(javax.jms.Session) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 2 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage 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();
        }
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) MessageConsumer(javax.jms.MessageConsumer) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(javax.jms.Connection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Header(org.apache.qpid.proton.amqp.messaging.Header) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) Session(javax.jms.Session) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 3 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage 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();
    }
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 4 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage 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();
    }
}
Also used : MQTT(org.fusesource.mqtt.client.MQTT) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) BlockingConnection(org.fusesource.mqtt.client.BlockingConnection) Topic(org.fusesource.mqtt.client.Topic) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 5 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage 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();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) Delivery(org.apache.qpid.proton.engine.Delivery) 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