Search in sources :

Example 6 with ActiveMQJMSConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory 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 7 with ActiveMQJMSConnectionFactory

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

the class AcknowledgementTest method testNonBlockingAckPerf.

/**
 * Ensure no blocking calls in acknowledge flow when block on acknowledge = false.
 * This is done by checking the performance compared to blocking is much improved.
 */
@Test
public void testNonBlockingAckPerf() throws Exception {
    getJmsServerManager().createConnectionFactory("testsuitecf1", false, JMSFactoryType.CF, NETTY_CONNECTOR, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_COMPRESS_LARGE_MESSAGES, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, true, true, true, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_MAX_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS, ActiveMQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION, null, "/testsuitecf1");
    getJmsServerManager().createConnectionFactory("testsuitecf2", false, JMSFactoryType.CF, NETTY_CONNECTOR, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_COMPRESS_LARGE_MESSAGES, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, true, true, true, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_MAX_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS, ActiveMQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION, null, "/testsuitecf2");
    ActiveMQJMSConnectionFactory cf1 = (ActiveMQJMSConnectionFactory) getInitialContext().lookup("/testsuitecf1");
    cf1.setBlockOnAcknowledge(false);
    ActiveMQJMSConnectionFactory cf2 = (ActiveMQJMSConnectionFactory) getInitialContext().lookup("/testsuitecf2");
    cf2.setBlockOnAcknowledge(true);
    int messageCount = 100;
    long sendT1 = send(cf1, queue1, messageCount);
    long sendT2 = send(cf2, queue2, messageCount);
    long time1 = consume(cf1, queue1, messageCount);
    long time2 = consume(cf2, queue2, messageCount);
    log.info("BlockOnAcknowledge=false MessageCount=" + messageCount + " TimeToConsume=" + time1);
    log.info("BlockOnAcknowledge=true MessageCount=" + messageCount + " TimeToConsume=" + time2);
    Assert.assertTrue(time1 < (time2 / 2));
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) Test(org.junit.Test)

Example 8 with ActiveMQJMSConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory 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 9 with ActiveMQJMSConnectionFactory

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

the class RestDeserializationTest method jmsSendMessage.

private void jmsSendMessage(Serializable value, String destName, boolean isQueue) throws JMSException {
    ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
    String jmsDest;
    if (isQueue) {
        jmsDest = QUEUE_QUALIFIED_PREFIX + destName;
    } else {
        jmsDest = TOPIC_QUALIFIED_PREFIX + destName;
    }
    Destination destination = ActiveMQDestination.fromPrefixedName(jmsDest);
    Connection conn = factory.createConnection();
    try {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(destination);
        ObjectMessage message = session.createObjectMessage();
        message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, "application/xml");
        message.setObject(value);
        producer.send(message);
    } finally {
        conn.close();
    }
}
Also used : ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Destination(javax.jms.Destination) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ObjectMessage(javax.jms.ObjectMessage) RestAMQConnection(org.apache.activemq.artemis.tests.integration.rest.util.RestAMQConnection) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 10 with ActiveMQJMSConnectionFactory

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

the class JMSClientTestSupport method createCoreConnection.

private Connection createCoreConnection(String connectionString, String username, String password, String clientId, boolean start) throws JMSException {
    ActiveMQJMSConnectionFactory factory = new ActiveMQJMSConnectionFactory(connectionString);
    Connection connection = trackJMSConnection(factory.createConnection(username, password));
    connection.setExceptionListener(new ExceptionListener() {

        @Override
        public void onException(JMSException exception) {
            exception.printStackTrace();
        }
    });
    if (clientId != null && !clientId.isEmpty()) {
        connection.setClientID(clientId);
    }
    if (start) {
        connection.start();
    }
    return connection;
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) Connection(javax.jms.Connection) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException)

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