Search in sources :

Example 1 with AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient 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 AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient 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 AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient 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 AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient 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 AmqpClient

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

the class AmqpSecurityTest method testSaslAuthWithAuthzid.

@Test(timeout = 60000)
public void testSaslAuthWithAuthzid() throws Exception {
    AmqpConnection connection = null;
    AmqpClient client = createAmqpClient(guestUser, guestPass);
    client.setAuthzid(guestUser);
    try {
        connection = client.connect();
    } catch (Exception ex) {
        fail("Should authenticate even with authzid set");
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Test(org.junit.Test)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)183 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)183 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)168 Test (org.junit.Test)158 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)123 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)114 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)91 Queue (org.apache.activemq.artemis.core.server.Queue)70 Source (org.apache.qpid.proton.amqp.messaging.Source)25 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)22 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)21 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)14 Receiver (org.apache.qpid.proton.engine.Receiver)12 CountDownLatch (java.util.concurrent.CountDownLatch)8 Map (java.util.Map)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)7 Sender (org.apache.qpid.proton.engine.Sender)7 URI (java.net.URI)6 HashMap (java.util.HashMap)6