Search in sources :

Example 71 with JMSContext

use of javax.jms.JMSContext in project activemq-artemis by apache.

the class JMSContextTest method sessionTransactedTestNoActiveJTATx.

@Test
public void sessionTransactedTestNoActiveJTATx() throws Exception {
    ((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = new DummyTransaction();
    JMSContext context = qraConnectionFactory.createContext(JMSContext.SESSION_TRANSACTED);
    assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE);
}
Also used : JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 72 with JMSContext

use of javax.jms.JMSContext in project activemq-artemis by apache.

the class JMSContextTest method clientAckTestNoActiveJTATx.

@Test
public void clientAckTestNoActiveJTATx() throws Exception {
    ((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = new DummyTransaction();
    JMSContext context = qraConnectionFactory.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
    assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE);
}
Also used : JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 73 with JMSContext

use of javax.jms.JMSContext in project activemq-artemis by apache.

the class OutgoingConnectionJTATest method testSimpleSendNoXAJMSContext.

@Test
public void testSimpleSendNoXAJMSContext() throws Exception {
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
        JMSContext jmsctx = qraConnectionFactory.createContext()) {
        session.start();
        // These next 4 lines could be written in a single line however it makes difficult for debugging
        JMSProducer producer = jmsctx.createProducer();
        producer.setProperty("strvalue", "hello");
        TextMessage msgsend = jmsctx.createTextMessage("hello");
        producer.send(q, msgsend);
        ClientMessage msg = consVerify.receive(1000);
        assertNotNull(msg);
        assertEquals("hello", msg.getStringProperty("strvalue"));
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) JMSProducer(javax.jms.JMSProducer) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Queue(javax.jms.Queue) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 74 with JMSContext

use of javax.jms.JMSContext in project activemq-artemis by apache.

the class ActiveMQServerTestCase method tearDown.

@After
public void tearDown() throws Exception {
    for (JMSContext context : contextSet) {
        context.close();
    }
    contextSet.clear();
    for (Connection localConn : connectionsSet) {
        localConn.close();
    }
    connectionsSet.clear();
}
Also used : Connection(javax.jms.Connection) JMSContext(javax.jms.JMSContext) After(org.junit.After)

Example 75 with JMSContext

use of javax.jms.JMSContext in project activemq-artemis by apache.

the class JMSAutoCloseableExample method main.

public static void main(final String[] args) throws Exception {
    // Step 2. Perfom a lookup on the queue
    Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
    // Step 4.Create a JMS Context using the try-with-resources statement
    try (// Even though ConnectionFactory is not closeable it would be nice to close an ActiveMQConnectionFactory
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
        JMSContext jmsContext = cf.createContext()) {
        // Step 5. create a jms producer
        JMSProducer jmsProducer = jmsContext.createProducer();
        // Step 6. Try sending a message, we don't have the appropriate privileges to do this so this will throw an exception
        jmsProducer.send(queue, "A Message from JMS2!");
        System.out.println("Received:" + jmsContext.createConsumer(queue).receiveBody(String.class));
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) JMSProducer(javax.jms.JMSProducer) Queue(javax.jms.Queue) JMSContext(javax.jms.JMSContext)

Aggregations

JMSContext (javax.jms.JMSContext)120 Test (org.junit.Test)57 JMSConsumer (javax.jms.JMSConsumer)44 ConnectionFactory (javax.jms.ConnectionFactory)35 Destination (javax.jms.Destination)30 TextMessage (javax.jms.TextMessage)28 JMSProducer (javax.jms.JMSProducer)27 Message (javax.jms.Message)18 JMSRuntimeException (javax.jms.JMSRuntimeException)13 TemporaryQueue (javax.jms.TemporaryQueue)13 InitialContext (javax.naming.InitialContext)12 JMSException (javax.jms.JMSException)10 Queue (javax.jms.Queue)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)7 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 QueueConnectionFactory (javax.jms.QueueConnectionFactory)4 Context (javax.naming.Context)4 NamingException (javax.naming.NamingException)4