Search in sources :

Example 91 with ActiveMQConnectionFactory

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

the class BridgeTestBase method setUpAdministeredObjects.

protected void setUpAdministeredObjects() throws Exception {
    cff0LowProducerWindow = new ConnectionFactoryFactory() {

        @Override
        public ConnectionFactory createConnectionFactory() throws Exception {
            ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            cf.setProducerWindowSize(100);
            return cf;
        }
    };
    cff0 = new ConnectionFactoryFactory() {

        @Override
        public ConnectionFactory createConnectionFactory() throws Exception {
            ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    cff0xa = new ConnectionFactoryFactory() {

        @Override
        public Object createConnectionFactory() throws Exception {
            ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    cf0 = (ConnectionFactory) cff0.createConnectionFactory();
    cf0xa = (XAConnectionFactory) cff0xa.createConnectionFactory();
    cff1 = new ConnectionFactoryFactory() {

        @Override
        public ConnectionFactory createConnectionFactory() throws Exception {
            ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    cff1xa = new ConnectionFactoryFactory() {

        @Override
        public XAConnectionFactory createConnectionFactory() throws Exception {
            ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    cf1 = (ConnectionFactory) cff1.createConnectionFactory();
    cf1xa = (XAConnectionFactory) cff1xa.createConnectionFactory();
    sourceQueueFactory = new DestinationFactory() {

        @Override
        public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/queue/sourceQueue");
        }
    };
    sourceQueue = (Queue) sourceQueueFactory.createDestination();
    targetQueueFactory = new DestinationFactory() {

        @Override
        public Destination createDestination() throws Exception {
            return (Destination) context1.lookup("/queue/targetQueue");
        }
    };
    targetQueue = (Queue) targetQueueFactory.createDestination();
    sourceTopicFactory = new DestinationFactory() {

        @Override
        public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/topic/sourceTopic");
        }
    };
    sourceTopic = (Topic) sourceTopicFactory.createDestination();
    localTargetQueueFactory = new DestinationFactory() {

        @Override
        public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/queue/localTargetQueue");
        }
    };
    localTargetQueue = (Queue) localTargetQueueFactory.createDestination();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) DestinationFactory(org.apache.activemq.artemis.jms.bridge.DestinationFactory) Destination(javax.jms.Destination) ActiveMQXAConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory) ActiveMQXAConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ActiveMQXAConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory)

Example 92 with ActiveMQConnectionFactory

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

the class BrowserTest method testBrowse2.

@Test
public void testBrowse2() throws Exception {
    conn = getConnectionFactory().createConnection();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(queue1);
    ActiveMQConnectionFactory cf1 = (ActiveMQConnectionFactory) getConnectionFactory();
    ClientSession coreSession = cf1.getServerLocator().createSessionFactory().createSession(true, true);
    coreSession.start();
    ClientConsumer browser = coreSession.createConsumer("Queue1", true);
    conn.start();
    Message m = session.createMessage();
    m.setIntProperty("cnt", 0);
    producer.send(m);
    Assert.assertNotNull(browser.receiveImmediate());
    coreSession.close();
    drainDestination(getConnectionFactory(), queue1);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) MessageProducer(javax.jms.MessageProducer) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Session(javax.jms.Session) Test(org.junit.Test)

Example 93 with ActiveMQConnectionFactory

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

the class ConnectionFactoryTest method testFactoryTypes.

@Test
public void testFactoryTypes() throws Exception {
    deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory");
    deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE");
    deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE_XA_FALSE", "/CF_QUEUE_XA_FALSE");
    deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE");
    deployConnectionFactory(0, JMSFactoryType.CF, "CF_XA_FALSE", "/CF_XA_FALSE");
    deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE");
    deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC");
    deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE");
    deployConnectionFactory(0, JMSFactoryType.CF, "CF_GENERIC", "/CF_GENERIC");
    deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_GENERIC_XA_TRUE", "/CF_GENERIC_XA_TRUE");
    deployConnectionFactory(0, JMSFactoryType.CF, "CF_GENERIC_XA_FALSE", "/CF_GENERIC_XA_FALSE");
    deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC_XA_FALSE", "/CF_TOPIC_XA_FALSE");
    ActiveMQConnectionFactory factory = null;
    factory = (ActiveMQConnectionFactory) ic.lookup("/ConnectionFactory");
    Assert.assertTrue(factory instanceof ConnectionFactory);
    assertNTypes(factory, 4);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_XA_TRUE");
    Assert.assertTrue(factory instanceof XAConnectionFactory);
    assertNTypes(factory, 6);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_XA_FALSE");
    Assert.assertTrue(factory instanceof ConnectionFactory);
    assertNTypes(factory, 4);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC");
    Assert.assertTrue(factory instanceof ConnectionFactory);
    assertNTypes(factory, 4);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC_XA_TRUE");
    Assert.assertTrue(factory instanceof XAConnectionFactory);
    assertNTypes(factory, 6);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC_XA_FALSE");
    Assert.assertTrue(factory instanceof ConnectionFactory);
    assertNTypes(factory, 4);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE");
    Assert.assertTrue(factory instanceof QueueConnectionFactory);
    assertNTypes(factory, 3);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE");
    Assert.assertTrue(factory instanceof XAQueueConnectionFactory);
    assertNTypes(factory, 4);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE_XA_FALSE");
    Assert.assertTrue(factory instanceof QueueConnectionFactory);
    assertNTypes(factory, 3);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC");
    Assert.assertTrue(factory instanceof TopicConnectionFactory);
    assertNTypes(factory, 3);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE");
    Assert.assertTrue(factory instanceof XATopicConnectionFactory);
    assertNTypes(factory, 4);
    factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC_XA_FALSE");
    Assert.assertTrue(factory instanceof TopicConnectionFactory);
    assertNTypes(factory, 3);
    undeployConnectionFactory("ConnectionFactory");
    undeployConnectionFactory("CF_QUEUE_XA_TRUE");
    undeployConnectionFactory("CF_QUEUE_XA_FALSE");
    undeployConnectionFactory("CF_XA_TRUE");
    undeployConnectionFactory("CF_XA_FALSE");
    undeployConnectionFactory("CF_QUEUE");
    undeployConnectionFactory("CF_TOPIC");
    undeployConnectionFactory("CF_TOPIC_XA_TRUE");
    undeployConnectionFactory("CF_GENERIC");
    undeployConnectionFactory("CF_GENERIC_XA_TRUE");
    undeployConnectionFactory("CF_GENERIC_XA_FALSE");
    undeployConnectionFactory("CF_TOPIC_XA_FALSE");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) XATopicConnectionFactory(javax.jms.XATopicConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) XAQueueConnectionFactory(javax.jms.XAQueueConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) XATopicConnectionFactory(javax.jms.XATopicConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) XAQueueConnectionFactory(javax.jms.XAQueueConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) XAQueueConnectionFactory(javax.jms.XAQueueConnectionFactory) XATopicConnectionFactory(javax.jms.XATopicConnectionFactory) Test(org.junit.Test)

Example 94 with ActiveMQConnectionFactory

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

the class ReferenceableTest method testReferenceCF.

@Test
public void testReferenceCF() throws Exception {
    Reference cfRef = ((Referenceable) cf).getReference();
    String factoryName = cfRef.getFactoryClassName();
    Class<?> factoryClass = Class.forName(factoryName);
    ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
    Object instance = factory.getObjectInstance(cfRef, null, null, null);
    ProxyAssertSupport.assertTrue(instance instanceof ActiveMQConnectionFactory);
    ActiveMQJMSConnectionFactory cf2 = (ActiveMQJMSConnectionFactory) instance;
    simpleSendReceive(cf2, queue1);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Referenceable(javax.naming.Referenceable) ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) Test(org.junit.Test)

Example 95 with ActiveMQConnectionFactory

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

the class ClusteredGroupingExample method main.

public static void main(String[] args) throws Exception {
    Connection connection0 = null;
    Connection connection1 = null;
    Connection connection2 = null;
    try {
        // Step 1. We will instantiate the queue object directly on this example
        // This could be done through JNDI or JMSession.createQueue
        Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
        // Step 2. create a connection factory towards server 0.
        ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616");
        // Step 3. create a connection factory towards server 1.
        ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617");
        // Step 4.  create a connection factory towards server 2.
        ConnectionFactory cf2 = new ActiveMQConnectionFactory("tcp://localhost:61618");
        // Step 5. We create a JMS Connection connection0 which is a connection to server 0
        connection0 = cf0.createConnection();
        // Step 6. We create a JMS Connection connection1 which is a connection to server 1
        connection1 = cf1.createConnection();
        // Step 7. We create a JMS Connection connection2 which is a connection to server 2
        connection2 = cf2.createConnection();
        // Step 8. We create a JMS Session on server 0
        Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Step 9. We create a JMS Session on server 1
        Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Step 10. We create a JMS Session on server 2
        Session session2 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Step 11. We start the connections to ensure delivery occurs on them
        connection0.start();
        connection1.start();
        connection2.start();
        // Step 12. We create JMS MessageConsumer objects on server 0
        MessageConsumer consumer = session0.createConsumer(queue);
        // Step 13. We create a JMS MessageProducer object on server 0, 1 and 2
        MessageProducer producer0 = session0.createProducer(queue);
        MessageProducer producer1 = session1.createProducer(queue);
        MessageProducer producer2 = session2.createProducer(queue);
        // Step 14. We send some messages to server 0, 1 and 2 with the same groupid set
        final int numMessages = 10;
        for (int i = 0; i < numMessages; i++) {
            TextMessage message = session0.createTextMessage("This is text message " + i);
            message.setStringProperty("JMSXGroupID", "Group-0");
            producer0.send(message);
            System.out.println("Sent messages: " + message.getText() + " to node 0");
        }
        for (int i = 0; i < numMessages; i++) {
            TextMessage message = session1.createTextMessage("This is text message " + (i + 10));
            message.setStringProperty("JMSXGroupID", "Group-0");
            producer1.send(message);
            System.out.println("Sent messages: " + message.getText() + " to node 1");
        }
        for (int i = 0; i < numMessages; i++) {
            TextMessage message = session2.createTextMessage("This is text message " + (i + 20));
            message.setStringProperty("JMSXGroupID", "Group-0");
            producer2.send(message);
            System.out.println("Sent messages: " + message.getText() + " to node 2");
        }
        for (int i = 0; i < numMessages * 3; i++) {
            TextMessage message0 = (TextMessage) consumer.receive(5000);
            System.out.println("Got message: " + message0.getText() + " from node 0");
        }
    } finally {
        if (connection0 != null) {
            connection0.close();
        }
        if (connection1 != null) {
            connection1.close();
        }
        if (connection2 != null) {
            connection2.close();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Aggregations

ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)221 Test (org.junit.Test)141 Connection (javax.jms.Connection)84 Session (javax.jms.Session)84 MessageProducer (javax.jms.MessageProducer)63 MessageConsumer (javax.jms.MessageConsumer)60 TextMessage (javax.jms.TextMessage)49 Queue (javax.jms.Queue)48 ConnectionFactory (javax.jms.ConnectionFactory)35 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)27 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)26 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)24 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)24 URI (java.net.URI)22 JMSException (javax.jms.JMSException)20 Message (javax.jms.Message)19 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)19 InitialContext (javax.naming.InitialContext)16 Context (javax.naming.Context)15 Hashtable (java.util.Hashtable)14