Search in sources :

Example 11 with JmsConnectionFactory

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

the class JMSWebSocketConnectionTest method testSendLargeMessageToClientFromAMQP.

@Ignore("Broker can't accept messages over 65535 right now")
@Test(timeout = 30000)
public void testSendLargeMessageToClientFromAMQP() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JmsConnection connection = (JmsConnection) factory.createConnection();
    sendLargeMessageViaAMQP();
    try {
        Session session = connection.createSession();
        Queue queue = session.createQueue(getQueueName());
        connection.start();
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(1000);
        assertNotNull(message);
        assertTrue(message instanceof BytesMessage);
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) BytesMessage(javax.jms.BytesMessage) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(javax.jms.Queue) Session(javax.jms.Session) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with JmsConnectionFactory

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

the class SaslKrb5LDAPSecurityTest method dotestJAASSecurityManagerAuthorizationPositive.

public void dotestJAASSecurityManagerAuthorizationPositive(String jaasConfigScope, String artemisRoleName) throws Exception {
    createArtemisServer(jaasConfigScope);
    Set<Role> roles = new HashSet<>();
    roles.add(new Role(artemisRoleName, true, true, true, true, true, true, true, true, true, true));
    server.getConfiguration().putSecurityRoles(QUEUE_NAME, roles);
    server.start();
    JmsConnectionFactory jmsConnectionFactory = new JmsConnectionFactory("amqp://localhost:5672?amqp.saslMechanisms=GSSAPI");
    Connection connection = jmsConnectionFactory.createConnection("client", null);
    try {
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        javax.jms.Queue queue = session.createQueue(QUEUE_NAME);
        // PRODUCE
        final String text = RandomUtil.randomString();
        try {
            MessageProducer producer = session.createProducer(queue);
            producer.send(session.createTextMessage(text));
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail("should not throw exception here");
        }
        // CONSUME
        try {
            MessageConsumer consumer = session.createConsumer(queue);
            TextMessage m = (TextMessage) consumer.receive(1000);
            Assert.assertNotNull(m);
            Assert.assertEquals(text, m.getText());
        } catch (Exception e) {
            Assert.fail("should not throw exception here");
        }
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) PrivilegedActionException(java.security.PrivilegedActionException) Role(org.apache.activemq.artemis.core.security.Role) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) HashSet(java.util.HashSet) Session(javax.jms.Session)

Example 13 with JmsConnectionFactory

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

the class AMQPToOpenwireTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = createServer(true, true);
    server.start();
    server.waitForActivation(10, TimeUnit.SECONDS);
    Configuration serverConfig = server.getConfiguration();
    serverConfig.getAddressesSettings().put("#", new AddressSettings().setAutoCreateQueues(false).setAutoCreateAddresses(false).setDeadLetterAddress(new SimpleString("ActiveMQ.DLQ")));
    serverConfig.setSecurityEnabled(false);
    coreQueue = new SimpleString(queueName);
    server.createQueue(coreQueue, RoutingType.ANYCAST, coreQueue, null, false, false);
    qpidfactory = new JmsConnectionFactory("amqp://localhost:61616");
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Before(org.junit.Before)

Example 14 with JmsConnectionFactory

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

the class AMQPQueueExample method main.

public static void main(String[] args) throws Exception {
    Connection connection = null;
    ConnectionFactory connectionFactory = new JmsConnectionFactory("amqp://localhost:5672");
    try {
        // Step 1. Create an amqp qpid 1.0 connection
        connection = connectionFactory.createConnection();
        // Step 2. Create a session
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Step 3. Create a sender
        Queue queue = session.createQueue("exampleQueue");
        MessageProducer sender = session.createProducer(queue);
        // Step 4. send a few simple message
        sender.send(session.createTextMessage("Hello world "));
        connection.start();
        // Step 5. create a moving receiver, this means the message will be removed from the queue
        MessageConsumer consumer = session.createConsumer(queue);
        // Step 7. receive the simple message
        TextMessage m = (TextMessage) consumer.receive(5000);
        System.out.println("message = " + m.getText());
    } finally {
        if (connection != null) {
            // Step 9. close the connection
            connection.close();
        }
    }
}
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)

Example 15 with JmsConnectionFactory

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

the class AMQPMessageLoadBalancingTest method testLoadBalanceAMQP.

@Test
public void testLoadBalanceAMQP() throws Exception {
    setupCluster(MessageLoadBalancingType.STRICT);
    startServers(0, 1);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    createQueue(0, "queues.0", "queues.0", null, true, null, null, RoutingType.ANYCAST);
    createQueue(1, "queues.0", "queues.0", null, true, null, null, RoutingType.ANYCAST);
    waitForBindings(0, "queues.0", 1, 0, true);
    waitForBindings(1, "queues.0", 1, 0, true);
    waitForBindings(0, "queues.0", 1, 0, false);
    waitForBindings(1, "queues.0", 1, 0, false);
    final int NUMBER_OF_MESSAGES = 100;
    // sending AMQP Messages.. they should be load balanced
    {
        JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
        Connection connection = factory.createConnection();
        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = session.createProducer(session.createQueue("queues.0"));
        for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
            producer.send(session.createTextMessage("hello " + i));
        }
        session.commit();
        connection.close();
    }
    receiveOnBothNodes(NUMBER_OF_MESSAGES);
    // If a user used a message type = 7, for messages that are not embedded,
    // it should still be treated as a normal message
    {
        ClientSession sessionProducer = sfs[0].createSession();
        ClientProducer producer = sessionProducer.createProducer("queues.0");
        for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
            // The user is mistakenly using the same type we used for embedded messages. it should still work
            ClientMessage message = sessionProducer.createMessage(Message.EMBEDDED_TYPE, true).putIntProperty("i", i);
            message.getBodyBuffer().writeString("hello!");
            producer.send(message);
            // will send 2 messages.. one with stuff, another empty
            message = sessionProducer.createMessage(Message.EMBEDDED_TYPE, true);
            producer.send(message);
        }
        receiveOnBothNodes(NUMBER_OF_MESSAGES * 2);
    }
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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