Search in sources :

Example 16 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class ActiveMQAMQPAdmin method createConnectionFactory.

@Override
public void createConnectionFactory(String name) {
    try {
        final JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
        context.bind(name, factory);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) NamingException(javax.naming.NamingException)

Example 17 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class TestSimpleExpire method testSendExpire.

@Test
public void testSendExpire() throws Exception {
    ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
    Connection connection = factory.createConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Queue queue = session.createQueue("q0");
    MessageProducer producer = session.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    producer.setTimeToLive(1000);
    for (int i = 0; i < 20000; i++) {
        producer.send(session.createTextMessage("expired"));
        if (i % 5000 == 0) {
            session.commit();
            System.out.println("Sent " + i + " + messages");
        }
    }
    session.commit();
    Thread.sleep(5000);
    producer.setTimeToLive(0);
    for (int i = 0; i < 500; i++) {
        producer.send(session.createTextMessage("ok"));
    }
    session.commit();
    MessageConsumer consumer = session.createConsumer(queue);
    connection.start();
    for (int i = 0; i < 500; i++) {
        TextMessage txt = (TextMessage) consumer.receive(10000);
        Assert.assertNotNull(txt);
        Assert.assertEquals("ok", txt.getText());
    }
    session.commit();
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 18 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class AmqpTransactionTest method testSendPersistentTX.

@Test(timeout = 120000)
public void testSendPersistentTX() throws Exception {
    int MESSAGE_COUNT = 2000;
    AtomicInteger errors = new AtomicInteger(0);
    server.createQueue(SimpleString.toSimpleString("q1"), RoutingType.ANYCAST, SimpleString.toSimpleString("q1"), null, true, false, 1, false, true);
    ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + AMQP_PORT);
    Connection sendConnection = factory.createConnection();
    Connection consumerConnection = factory.createConnection();
    try {
        Thread receiverThread = new Thread() {

            @Override
            public void run() {
                try {
                    consumerConnection.start();
                    Session consumerSession = consumerConnection.createSession(true, Session.SESSION_TRANSACTED);
                    javax.jms.Queue q1 = consumerSession.createQueue("q1");
                    MessageConsumer consumer = consumerSession.createConsumer(q1);
                    for (int i = 1; i <= MESSAGE_COUNT; i++) {
                        Message message = consumer.receive(5000);
                        if (message == null) {
                            throw new IOException("No message read in time.");
                        }
                        if (i % 100 == 0) {
                            if (i % 1000 == 0)
                                System.out.println("Read message " + i);
                            consumerSession.commit();
                        }
                    }
                    // Assure that all messages are consumed
                    consumerSession.commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    errors.incrementAndGet();
                }
            }
        };
        receiverThread.start();
        Session sendingSession = sendConnection.createSession(true, Session.SESSION_TRANSACTED);
        javax.jms.Queue q1 = sendingSession.createQueue("q1");
        MessageProducer producer = sendingSession.createProducer(q1);
        producer.setDeliveryDelay(DeliveryMode.NON_PERSISTENT);
        for (int i = 0; i < MESSAGE_COUNT; i++) {
            producer.send(sendingSession.createTextMessage("message " + i), DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
            if (i % 100 == 0) {
                if (i % 1000 == 0)
                    System.out.println("Sending " + i);
                sendingSession.commit();
            }
        }
        sendingSession.commit();
        receiverThread.join(50000);
        Assert.assertFalse(receiverThread.isAlive());
        Assert.assertEquals(0, errors.get());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sendConnection.close();
        consumerConnection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(javax.jms.Connection) IOException(java.io.IOException) IOException(java.io.IOException) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 19 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class AmqpFailoverEndpointDiscoveryTest method testFailoverListWithAMQP.

@Test(timeout = 120000)
public void testFailoverListWithAMQP() throws Exception {
    JmsConnectionFactory factory = getJmsConnectionFactory();
    try (Connection connection = factory.createConnection()) {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        javax.jms.Queue queue = session.createQueue(ADDRESS.toString());
        MessageProducer producer = session.createProducer(queue);
        producer.send(session.createTextMessage("hello before failover"));
        liveServer.crash(true, true);
        producer.send(session.createTextMessage("hello after failover"));
        MessageConsumer consumer = session.createConsumer(queue);
        connection.start();
        TextMessage receive = (TextMessage) consumer.receive(5000);
        Assert.assertNotNull(receive);
        Assert.assertEquals("hello before failover", receive.getText());
        receive = (TextMessage) consumer.receive(5000);
        Assert.assertEquals("hello after failover", receive.getText());
        Assert.assertNotNull(receive);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 20 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class AmqpDescribedTypePayloadTest method testDescribedTypeMessageRoundTrips.

@Test(timeout = 60000)
public void testDescribedTypeMessageRoundTrips() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    // Send with AMQP client.
    AmqpSender sender = session.createSender(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setDescribedType(new AmqpNoLocalFilter());
    sender.send(message);
    sender.close();
    Queue queue = getProxyToQueue(getQueueName());
    Wait.assertEquals(1, queue::getMessageCount);
    // Receive and resend with Qpid JMS client
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    Connection jmsConnection = factory.createConnection();
    try {
        Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = jmsSession.createQueue(getName());
        MessageConsumer jmsConsumer = jmsSession.createConsumer(destination);
        jmsConnection.start();
        Message received = jmsConsumer.receive(5000);
        assertNotNull(received);
        assertTrue(received instanceof ObjectMessage);
        MessageProducer jmsProducer = jmsSession.createProducer(destination);
        jmsProducer.send(received);
    } finally {
        jmsConnection.close();
    }
    assertEquals(1, queue.getMessageCount());
    // Now lets receive it with AMQP and see that we get back what we expected.
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    receiver.flow(1);
    AmqpMessage returned = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(returned);
    assertNotNull(returned.getDescribedType());
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) Connection(javax.jms.Connection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpNoLocalFilter(org.apache.activemq.transport.amqp.client.AmqpNoLocalFilter) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ObjectMessage(javax.jms.ObjectMessage) MessageProducer(javax.jms.MessageProducer) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

JmsConnectionFactory (org.apache.qpid.jms.JmsConnectionFactory)40 Connection (javax.jms.Connection)19 Session (javax.jms.Session)19 MessageConsumer (javax.jms.MessageConsumer)17 MessageProducer (javax.jms.MessageProducer)17 Test (org.junit.Test)17 TextMessage (javax.jms.TextMessage)14 ConnectionFactory (javax.jms.ConnectionFactory)10 Queue (javax.jms.Queue)10 Message (javax.jms.Message)8 BytesMessage (javax.jms.BytesMessage)4 JmsConnection (org.apache.qpid.jms.JmsConnection)4 JMSException (javax.jms.JMSException)3 Topic (javax.jms.Topic)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 AMQPComponent (org.apache.camel.component.amqp.AMQPComponent)3 URI (java.net.URI)2 JMSSecurityException (javax.jms.JMSSecurityException)2 InitialContext (javax.naming.InitialContext)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2