Search in sources :

Example 31 with JmsConnectionFactory

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

the class ArtemisAMQPClientFeatureIT method testArtemisAMQPClient.

@Test
public void testArtemisAMQPClient() throws Exception {
    // setup connection
    ConnectionFactory connectionFactory = new JmsConnectionFactory("amqp://localhost:5672");
    try (Connection connection = connectionFactory.createConnection()) {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // send message
        Queue queue = session.createQueue("artemisAMPQClientFeatureITQueue");
        MessageProducer sender = session.createProducer(queue);
        String message = "Hello world ";
        sender.send(session.createTextMessage(message));
        // receive message and assert
        connection.start();
        MessageConsumer consumer = session.createConsumer(queue);
        TextMessage m = (TextMessage) consumer.receive(5000);
        assertEquals(message, m.getText());
    }
}
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 32 with JmsConnectionFactory

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

the class ArtemisFeatureTest method test.

@Test(timeout = 5 * 60 * 1000)
public void test() throws Throwable {
    executeCommand("bundle:list");
    withinReason(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            assertTrue("artemis bundle installed", verifyBundleInstalled("artemis-server-osgi"));
            return true;
        }
    });
    Object service = waitForService("(objectClass=org.apache.activemq.artemis.core.server.ActiveMQServer)", 30000);
    assertNotNull(service);
    LOG.info("have service " + service);
    executeCommand("service:list -n");
    Connection connection = null;
    try {
        JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:5672");
        connection = factory.createConnection(USER, PASSWORD);
        connection.start();
        QueueSession sess = (QueueSession) connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        Queue queue = sess.createQueue("exampleQueue");
        MessageProducer producer = sess.createProducer(queue);
        producer.send(sess.createTextMessage("TEST"));
        // Test browsing
        try (QueueBrowser browser = sess.createBrowser(queue)) {
            Enumeration messages = browser.getEnumeration();
            while (messages.hasMoreElements()) {
                messages.nextElement();
            }
        }
        // Test management
        Queue managementQueue = sess.createQueue("activemq.management");
        QueueRequestor requestor = new QueueRequestor(sess, managementQueue);
        connection.start();
        TextMessage m = sess.createTextMessage();
        m.setStringProperty("_AMQ_ResourceName", "broker");
        m.setStringProperty("_AMQ_OperationName", "getQueueNames");
        m.setText("[\"ANYCAST\"]");
        Message reply = requestor.request(m);
        String json = ((TextMessage) reply).getText();
        JsonArray array = Json.createReader(new StringReader(json)).readArray();
        List<JsonString> queues = (List<JsonString>) array.get(0);
        assertNotNull(queues);
        assertFalse(queues.isEmpty());
        MessageConsumer consumer = sess.createConsumer(queue);
        Message msg = consumer.receive(5000);
        assertNotNull(msg);
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Enumeration(java.util.Enumeration) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) JsonString(javax.json.JsonString) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) JsonArray(javax.json.JsonArray) QueueRequestor(javax.jms.QueueRequestor) StringReader(java.io.StringReader) List(java.util.List) ArrayList(java.util.ArrayList) MessageProducer(javax.jms.MessageProducer) JsonString(javax.json.JsonString) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) QueueBrowser(javax.jms.QueueBrowser) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 33 with JmsConnectionFactory

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

the class PerfBase method init.

private void init() throws Exception {
    if (perfParams.isOpenwire()) {
        factory = new org.apache.activemq.ActiveMQConnectionFactory(perfParams.getUri());
        destination = new org.apache.activemq.command.ActiveMQQueue(perfParams.getDestinationName());
        connection = factory.createConnection();
    } else if (perfParams.isCore()) {
        factory = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory(perfParams.getUri());
        destination = new org.apache.activemq.artemis.jms.client.ActiveMQQueue(perfParams.getDestinationName());
        connection = factory.createConnection();
    } else if (perfParams.isAMQP()) {
        factory = new JmsConnectionFactory(perfParams.getUri());
        destination = new org.apache.activemq.artemis.jms.client.ActiveMQQueue(perfParams.getDestinationName());
        connection = factory.createConnection();
        Session sessionX = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        destination = sessionX.createQueue(perfParams.getDestinationName());
        sessionX.close();
    }
    session = connection.createSession(perfParams.isSessionTransacted(), perfParams.isDupsOK() ? Session.DUPS_OK_ACKNOWLEDGE : Session.AUTO_ACKNOWLEDGE);
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Session(javax.jms.Session)

Example 34 with JmsConnectionFactory

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

the class InterceptorExample method main.

public static void main(final String[] args) throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
    try (Connection connection = factory.createConnection()) {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue interceptorQueue = session.createQueue("interceptorQueue");
        MessageProducer producer = session.createProducer(interceptorQueue);
        TextMessage textMessage = session.createTextMessage("A text message");
        textMessage.setStringProperty("SimpleAmqpInterceptor", "SimpleAmqpInterceptorValue");
        producer.send(textMessage);
    }
}
Also used : 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)

Example 35 with JmsConnectionFactory

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

the class BrokerPluginExample method sendConsumeAMQP.

private static void sendConsumeAMQP() throws JMSException {
    Connection connection = null;
    ConnectionFactory connectionFactory = new JmsConnectionFactory("amqp://localhost:5672");
    try {
        // Create an amqp qpid 1.0 connection
        connection = connectionFactory.createConnection();
        // Create a session
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Create a sender
        Queue queue = session.createQueue("exampleQueue");
        MessageProducer sender = session.createProducer(queue);
        // send a few simple message
        sender.send(session.createTextMessage("Hello world "));
        connection.start();
        // create a moving receiver, this means the message will be removed from the queue
        MessageConsumer consumer = session.createConsumer(queue);
        // receive the simple message
        TextMessage m = (TextMessage) consumer.receive(5000);
        if (m.getStringProperty("count") == null) {
            throw new RuntimeException(("missed property count"));
        }
        System.out.println("message = " + m.getText() + " property count (added by interceptor = " + m.getStringProperty("count") + ")");
    } finally {
        if (connection != null) {
            // close the connection
            connection.close();
        }
    }
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) 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) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

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