Search in sources :

Example 16 with ActiveMQJMSConnectionFactory

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

the class JMSBridgeImplTest method testStartWithSpecificTCCL.

@Test
public void testStartWithSpecificTCCL() throws Exception {
    MockContextClassLoader mockTccl = setMockTCCL();
    try {
        final AtomicReference<Connection> sourceConn = new AtomicReference<>();
        ActiveMQJMSConnectionFactory failingSourceCF = new ActiveMQJMSConnectionFactory(false, new TransportConfiguration(InVMConnectorFactory.class.getName())) {

            private static final long serialVersionUID = -8866390811966688830L;

            @Override
            public Connection createConnection() throws JMSException {
                sourceConn.set(super.createConnection());
                return sourceConn.get();
            }
        };
        // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
        failingSourceCF.setReconnectAttempts(0);
        failingSourceCF.setBlockOnNonDurableSend(true);
        failingSourceCF.setBlockOnDurableSend(true);
        ConnectionFactoryFactory sourceCFF = JMSBridgeImplTest.newTCCLAwareConnectionFactoryFactory(failingSourceCF);
        ConnectionFactoryFactory targetCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
        DestinationFactory sourceDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
        DestinationFactory targetDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
        TransactionManager tm = JMSBridgeImplTest.newTransactionManager();
        JMSBridgeImpl bridge = new JMSBridgeImpl();
        Assert.assertNotNull(bridge);
        bridge.setSourceConnectionFactoryFactory(sourceCFF);
        bridge.setSourceDestinationFactory(sourceDF);
        bridge.setTargetConnectionFactoryFactory(targetCFF);
        bridge.setTargetDestinationFactory(targetDF);
        bridge.setFailureRetryInterval(10);
        bridge.setMaxRetries(2);
        bridge.setMaxBatchSize(1);
        bridge.setMaxBatchTime(-1);
        bridge.setTransactionManager(tm);
        bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
        Assert.assertFalse(bridge.isStarted());
        bridge.start();
        Assert.assertTrue(bridge.isStarted());
        unsetMockTCCL(mockTccl);
        tcclClassFound.set(false);
        sourceConn.get().getExceptionListener().onException(new JMSException("exception on the source"));
        Thread.sleep(4 * bridge.getFailureRetryInterval());
        // reconnection must have succeeded
        Assert.assertTrue(bridge.isStarted());
        bridge.stop();
        Assert.assertFalse(bridge.isStarted());
        assertTrue(tcclClassFound.get());
    } finally {
        if (mockTccl != null)
            unsetMockTCCL(mockTccl);
    }
}
Also used : DestinationFactory(org.apache.activemq.artemis.jms.bridge.DestinationFactory) JMSBridgeImpl(org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) TransactionManager(javax.transaction.TransactionManager) Connection(javax.jms.Connection) ConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 17 with ActiveMQJMSConnectionFactory

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

the class ArtemisJMSClientFeatureIT method testArtemisJMSClient.

@Test
public void testArtemisJMSClient() throws Exception {
    // setup connection
    ConnectionFactory cf = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
    try (Connection connection = cf.createConnection()) {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        connection.start();
        Queue queue = ActiveMQJMSClient.createQueue("artemisJMSClientFeatureITQueue");
        MessageProducer producer = session.createProducer(queue);
        // send message
        String textMessage = "This is a text message";
        TextMessage message = session.createTextMessage(textMessage);
        producer.send(message);
        // receive message and assert
        MessageConsumer messageConsumer = session.createConsumer(queue);
        TextMessage messageReceived = (TextMessage) messageConsumer.receive(100);
        assertEquals(textMessage, messageReceived.getText());
    }
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) 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 ActiveMQJMSConnectionFactory

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

the class JMSUtil method createFactory.

public static ConnectionFactory createFactory(final String connectorFactory, final long connectionTTL, final long clientFailureCheckPeriod) throws JMSException {
    ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(connectorFactory));
    cf.setBlockOnNonDurableSend(true);
    cf.setBlockOnDurableSend(true);
    cf.setBlockOnAcknowledge(true);
    cf.setConnectionTTL(connectionTTL);
    cf.setClientFailureCheckPeriod(clientFailureCheckPeriod);
    return cf;
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 19 with ActiveMQJMSConnectionFactory

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

the class JMSUtil method createConnection.

// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
public static Connection createConnection(final String connectorFactory) throws JMSException {
    ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(connectorFactory));
    cf.setBlockOnNonDurableSend(true);
    cf.setBlockOnDurableSend(true);
    cf.setBlockOnAcknowledge(true);
    return cf.createConnection();
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 20 with ActiveMQJMSConnectionFactory

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

the class PagingOrderTest method testPagingOverCreatedDestinationTopics.

@Test
public void testPagingOverCreatedDestinationTopics() throws Exception {
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());
    JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    InVMNamingContext context = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(context));
    jmsServer.start();
    jmsServer.createTopic(true, "tt", "/topic/TT");
    server.getActiveMQServerControl().addAddressSettings("TT", "DLQ", "DLQ", -1, false, 5, 1024 * 1024, 1024 * 10, 5, 5, 1, 1000, 0, false, "PAGE", -1, 10, "KILL", true, true, true, true);
    ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    Connection conn = cf.createConnection();
    conn.setClientID("tst");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = (Topic) context.lookup("/topic/TT");
    sess.createDurableSubscriber(topic, "t1");
    MessageProducer prod = sess.createProducer(topic);
    prod.setDeliveryMode(DeliveryMode.PERSISTENT);
    TextMessage txt = sess.createTextMessage("TST");
    prod.send(txt);
    PagingStore store = server.getPagingManager().getPageStore(new SimpleString("TT"));
    assertEquals(1024 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());
    jmsServer.stop();
    server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());
    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(context));
    jmsServer.start();
    AddressSettings settings = server.getAddressSettingsRepository().getMatch("TT");
    assertEquals(1024 * 1024, settings.getMaxSizeBytes());
    assertEquals(10 * 1024, settings.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());
    store = server.getPagingManager().getPageStore(new SimpleString("TT"));
    conn.close();
    server.stop();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HashMap(java.util.HashMap) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) TextMessage(javax.jms.TextMessage) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

ActiveMQJMSConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)13 Connection (javax.jms.Connection)12 Test (org.junit.Test)11 Session (javax.jms.Session)9 ConnectionFactory (javax.jms.ConnectionFactory)8 MessageProducer (javax.jms.MessageProducer)7 Destination (javax.jms.Destination)6 JMSException (javax.jms.JMSException)6 ConnectionFactoryFactory (org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory)6 DestinationFactory (org.apache.activemq.artemis.jms.bridge.DestinationFactory)6 TransactionManager (javax.transaction.TransactionManager)5 JMSBridgeImpl (org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl)5 ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)5 MessageConsumer (javax.jms.MessageConsumer)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ObjectMessage (javax.jms.ObjectMessage)3 TextMessage (javax.jms.TextMessage)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 HashMap (java.util.HashMap)2