Search in sources :

Example 51 with ActiveMQConnectionFactory

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

the class ActiveMQConnectionFactoryTest method receiveObjectMessage.

private Object receiveObjectMessage(String blackList, String whiteList, String qname, Serializable obj, boolean useJndi, boolean useBrowser) throws Exception {
    sendObjectMessage(qname, obj);
    StringBuilder query = new StringBuilder("");
    if (blackList != null) {
        query.append("?");
        query.append("deserializationBlackList=");
        query.append(blackList);
        if (whiteList != null) {
            query.append("&");
            query.append("deserializationWhiteList=");
            query.append(whiteList);
        }
    } else {
        if (whiteList != null) {
            query.append("?deserializationWhiteList=");
            query.append(whiteList);
        }
    }
    System.out.println("query string: " + query);
    ActiveMQConnectionFactory factory = null;
    if (useJndi) {
        Hashtable<String, Object> props = new Hashtable<>();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
        props.put("connectionFactory.VmConnectionFactory", "vm://0" + query);
        Context ctx = new InitialContext(props);
        factory = (ActiveMQConnectionFactory) ctx.lookup("VmConnectionFactory");
    } else {
        factory = new ActiveMQConnectionFactory("vm://0" + query);
    }
    try (Connection connection = factory.createConnection()) {
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(qname);
        Object result = null;
        if (useBrowser) {
            QueueBrowser browser = session.createBrowser(queue);
            ObjectMessage objMessage = (ObjectMessage) browser.getEnumeration().nextElement();
            // drain message before triggering deserialization
            MessageConsumer consumer = session.createConsumer(queue);
            consumer.receive(5000);
            result = objMessage.getObject();
        } else {
            MessageConsumer consumer = session.createConsumer(queue);
            ObjectMessage objMessage = (ObjectMessage) consumer.receive(5000);
            assertNotNull(objMessage);
            result = objMessage.getObject();
        }
        return result;
    } catch (Exception e) {
        return e;
    }
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) MessageConsumer(javax.jms.MessageConsumer) Hashtable(java.util.Hashtable) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InitialContext(javax.naming.InitialContext) JMSException(javax.jms.JMSException) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ObjectMessage(javax.jms.ObjectMessage) Queue(javax.jms.Queue) QueueBrowser(javax.jms.QueueBrowser) Session(javax.jms.Session)

Example 52 with ActiveMQConnectionFactory

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

the class ActiveMQConnectionFactoryTest method testDefaultConstructorAndSetConnectorPairs.

@Test
public void testDefaultConstructorAndSetConnectorPairs() throws Exception {
    ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);
    assertFactoryParams(cf, new TransportConfiguration[] { liveTC }, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, 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_DISCOVERY_INITIAL_WAIT_TIMEOUT, 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_RECONNECT_ATTEMPTS);
    Connection conn = cf.createConnection();
    conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    testSettersThrowException(cf);
    conn.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Connection(javax.jms.Connection) Test(org.junit.Test)

Example 53 with ActiveMQConnectionFactory

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

the class ActiveMQConnectionFactoryTest method testStaticConnectorListConstructor.

@Test
public void testStaticConnectorListConstructor() throws Exception {
    ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);
    assertFactoryParams(cf, new TransportConfiguration[] { liveTC }, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, 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_DISCOVERY_INITIAL_WAIT_TIMEOUT, 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_RECONNECT_ATTEMPTS);
    Connection conn = cf.createConnection();
    conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    testSettersThrowException(cf);
    conn.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Connection(javax.jms.Connection) Test(org.junit.Test)

Example 54 with ActiveMQConnectionFactory

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

the class ActiveMQConnectionFactoryTest method testDefaultConstructor.

@Test
public void testDefaultConstructor() throws Exception {
    ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF);
    assertFactoryParams(cf, null, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, 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_DISCOVERY_INITIAL_WAIT_TIMEOUT, 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_RECONNECT_ATTEMPTS);
    Connection conn = null;
    try {
        conn = cf.createConnection();
        conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Assert.fail("Should throw exception");
    } catch (JMSException e) {
    // Ok
    }
    if (conn != null) {
        conn.close();
    }
    ActiveMQConnectionFactoryTest.log.info("Got here");
    testSettersThrowException(cf);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 55 with ActiveMQConnectionFactory

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

the class ActiveMQConnectionFactoryTest method sendObjectMessage.

private void sendObjectMessage(String qname, Serializable obj) throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://0");
    Connection connection = factory.createConnection();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue q = session.createQueue(qname);
        MessageProducer producer = session.createProducer(q);
        ObjectMessage objMessage = session.createObjectMessage();
        objMessage.setObject(obj);
        producer.send(objMessage);
    } finally {
        connection.close();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ObjectMessage(javax.jms.ObjectMessage) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) 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