Search in sources :

Example 86 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class CustomConnectionFactoryNameTest method testConnectionFactoriesAreConfigured.

public void testConnectionFactoriesAreConfigured() throws NamingException {
    super.testConnectionFactoriesArePresent();
    ActiveMQConnectionFactory factory1 = (ActiveMQConnectionFactory) context.lookup("jms/Connection");
    assertNull(factory1.getClientID());
    ActiveMQConnectionFactory factory2 = (ActiveMQConnectionFactory) context.lookup("jms/DURABLE_SUB_CONNECTION_FACTORY");
    assertEquals("testclient", factory2.getClientID());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory)

Example 87 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class InitialContextTest method testConnectionFactoryPolicyConfig.

public void testConnectionFactoryPolicyConfig() throws Exception {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    properties.put(Context.PROVIDER_URL, "tcp://localhost:65432");
    properties.put("prefetchPolicy.queuePrefetch", "777");
    properties.put("redeliveryPolicy.maximumRedeliveries", "15");
    properties.put("redeliveryPolicy.backOffMultiplier", "32");
    InitialContext context = new InitialContext(properties);
    ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
    assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
    assertEquals(777, connectionFactory.getPrefetchPolicy().getQueuePrefetch());
    assertEquals(15, connectionFactory.getRedeliveryPolicy().getMaximumRedeliveries());
    assertEquals(32d, connectionFactory.getRedeliveryPolicy().getBackOffMultiplier());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

Example 88 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class InitialContextTest method testUsingStandardJNDIKeys.

public void testUsingStandardJNDIKeys() throws Exception {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    String expected = "tcp://localhost:65432";
    properties.put(Context.PROVIDER_URL, expected);
    InitialContext context = new InitialContext(properties);
    ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
    assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
    assertEquals("the brokerURL should match", expected, connectionFactory.getBrokerURL());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

Example 89 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class FQQNOpenWireTest method testFQNConsumer.

@Test
public void testFQNConsumer() throws Exception {
    Connection exConn = null;
    SimpleString durableQueue = new SimpleString("myqueue");
    this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
    try {
        ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
        exConn = exFact.createConnection();
        exConn.start();
        Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue(durableQueue.toString());
        MessageProducer producer = session.createProducer(destination);
        TextMessage message = session.createTextMessage("This is a text message");
        producer.send(message);
        Destination destinationFQN = session.createQueue(CompositeAddress.toFullQN(durableQueue, durableQueue).toString());
        MessageConsumer messageConsumer = session.createConsumer(destinationFQN);
        TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        assertEquals("This is a text message", messageReceived.getText());
    } finally {
        if (exConn != null) {
            exConn.close();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 90 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class FQQNOpenWireTest method testVirtualTopicFQQNAutoCreateQAndAddress.

@Test
public void testVirtualTopicFQQNAutoCreateQAndAddress() throws Exception {
    Connection exConn = null;
    SimpleString topic = new SimpleString("VirtualTopic.Orders");
    SimpleString subscriptionQ = new SimpleString("Consumer.A");
    // defaults are false via test setUp
    this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
    this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);
    try {
        ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
        exFact.setWatchTopicAdvisories(false);
        exConn = exFact.createConnection();
        exConn.start();
        Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createTopic(topic.toString());
        MessageProducer producer = session.createProducer(destination);
        Destination destinationFQN = session.createQueue(CompositeAddress.toFullQN(topic, subscriptionQ).toString());
        MessageConsumer messageConsumerA = session.createConsumer(destinationFQN);
        MessageConsumer messageConsumerB = session.createConsumer(destinationFQN);
        TextMessage message = session.createTextMessage("This is a text message");
        producer.send(message);
        // only one consumer should get the message
        TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
        TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);
        assertTrue((messageReceivedA == null || messageReceivedB == null));
        String text = messageReceivedA != null ? messageReceivedA.getText() : messageReceivedB.getText();
        assertEquals("This is a text message", text);
        messageConsumerA.close();
        messageConsumerB.close();
    } finally {
        if (exConn != null) {
            exConn.close();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)436 Session (javax.jms.Session)148 Connection (javax.jms.Connection)144 Test (org.junit.Test)107 MessageConsumer (javax.jms.MessageConsumer)103 TextMessage (javax.jms.TextMessage)81 MessageProducer (javax.jms.MessageProducer)79 Message (javax.jms.Message)74 Queue (javax.jms.Queue)66 JMSException (javax.jms.JMSException)65 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)51 ConnectionFactory (javax.jms.ConnectionFactory)48 Destination (javax.jms.Destination)42 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)36 BrokerService (org.apache.activemq.broker.BrokerService)32 CountDownLatch (java.util.concurrent.CountDownLatch)28 Before (org.junit.Before)27 MessageListener (javax.jms.MessageListener)26 CamelContext (org.apache.camel.CamelContext)26 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)23