Search in sources :

Example 66 with JMSContext

use of javax.jms.JMSContext in project wildfly by wildfly.

the class ClusteredMessagingTestCase method receiveMessage.

protected static void receiveMessage(Context ctx, String destinationLookup, String expectedText) throws NamingException {
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    Destination destination = (Destination) ctx.lookup(destinationLookup);
    assertNotNull(destination);
    try (JMSContext context = cf.createContext("guest", "guest")) {
        JMSConsumer consumer = context.createConsumer(destination);
        receiveMessage(consumer, expectedText);
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext)

Example 67 with JMSContext

use of javax.jms.JMSContext in project wildfly by wildfly.

the class ClusteredMessagingTestCase method createJMSContext.

protected static JMSContext createJMSContext(Context ctx) throws NamingException {
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    JMSContext context = cf.createContext("guest", "guest");
    return context;
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) JMSContext(javax.jms.JMSContext)

Example 68 with JMSContext

use of javax.jms.JMSContext in project wildfly by wildfly.

the class ClusteredMessagingTestCase method sendMessage.

protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException {
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    Destination destination = (Destination) ctx.lookup(destinationLookup);
    assertNotNull(destination);
    try (JMSContext context = cf.createContext("guest", "guest")) {
        context.createProducer().send(destination, text);
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSContext(javax.jms.JMSContext)

Example 69 with JMSContext

use of javax.jms.JMSContext in project Payara by payara.

the class InjectableJMSContext method toString.

@Override
public String toString() {
    JMSContext rContext = null;
    JMSContext tContext = null;
    try {
        boolean isInTransaction = isInTransaction();
        if (isInTransaction) {
            TransactedJMSContextManager manager = getTransactedManager();
            tContext = manager.getContext(id);
            if (tContext == null)
                tContext = manager.getContext(ipId, id, metadata, getConnectionFactory(isInTransaction));
        } else {
            rContext = requestedManager.getContext(id);
            if (rContext == null)
                rContext = requestedManager.getContext(ipId, id, metadata, getConnectionFactory(isInTransaction));
        }
    } catch (ContextNotActiveException cnae) {
    // if toString() is called in an env which doesn't have valid CDI request/transaction scope,
    // then we don't call the CDI proxy for creating a new JMSContext bean.
    }
    StringBuffer sb = new StringBuffer();
    sb.append("JMSContext Wrapper ").append(ipId).append(" with metadata [").append(metadata).append("]");
    if (tContext != null)
        sb.append(", around ").append(getTransactedManager().getType()).append(" [").append(tContext).append("]");
    else if (rContext != null)
        sb.append(", around ").append(requestedManager.getType()).append(" [").append(rContext).append("]");
    else
        sb.append(", there is neither a transaction or a valid request scope.");
    return sb.toString();
}
Also used : ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) JMSContext(javax.jms.JMSContext)

Example 70 with JMSContext

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

the class JMSContextTest method testCreateContextThrowsException.

@Test
public void testCreateContextThrowsException() throws Exception {
    JMSContext jmsctx = qraConnectionFactory.createContext();
    try {
        jmsctx.createContext(JMSContext.AUTO_ACKNOWLEDGE);
        fail("expected JMSRuntimeException");
    } catch (JMSRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("wrong exception thrown: " + e);
    }
}
Also used : JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

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