Search in sources :

Example 36 with JMSContext

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

the class ScopedInjectedJMSContextTestCase method transactionScoped.

/**
 * Test that a transaction-scoped JMSContext is properly cleaned up after the transaction completion.
 */
@Test
public void transactionScoped() throws Exception {
    String text = UUID.randomUUID().toString();
    try (JMSContext context = factory.createContext()) {
        context.createProducer().setDeliveryMode(NON_PERSISTENT).send(queueForTransactionScope, text);
        assertTrue(transactedConsumer.receive(queueForTransactionScope, text));
    }
}
Also used : JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 37 with JMSContext

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

the class InjectedJMSContextTestCase method sendAndReceiveWithContext.

@Test
public void sendAndReceiveWithContext() throws JMSException {
    String text = UUID.randomUUID().toString();
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue tempQueue = context.createTemporaryQueue();
        context.createProducer().send(tempQueue, text);
        assertMessageIsReceived(tempQueue, context, text, false);
    }
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 38 with JMSContext

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

the class InjectedJMSContextTestCase method tearDown.

@After
public void tearDown() throws JMSException {
    // drain the queue to remove any pending messages from it
    try (JMSContext context = factory.createContext()) {
        JMSConsumer consumer = context.createConsumer(queue);
        Message m;
        do {
            m = consumer.receiveNoWait();
        } while (m != null);
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) Message(javax.jms.Message) JMSContext(javax.jms.JMSContext) After(org.junit.After)

Example 39 with JMSContext

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

the class MessagingBean method checkAnnotationBasedDefinitionsWithVaultedAttributes.

public void checkAnnotationBasedDefinitionsWithVaultedAttributes() {
    assertNotNull(factory5);
    // verify authentication using vaulted attributes works fine
    JMSContext context = factory5.createContext();
    assertNotNull(context);
    context.close();
}
Also used : JMSContext(javax.jms.JMSContext)

Example 40 with JMSContext

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

the class EJB2xMDB method onMessage.

@Override
public void onMessage(Message message) {
    logger.trace("Received message " + message + " in MDB " + this.getClass().getName());
    try {
        if (message.getStringProperty("MessageFormat") != null)
            logger.trace("MessageFormat property = " + message.getStringProperty("MessageFormat"));
        Destination replyTo = message.getJMSReplyTo();
        if (replyTo == null) {
            try {
                logger.trace("mdbContext = " + mdbContext);
                replyTo = (Destination) mdbContext.lookup("jms/replyQueue");
            } catch (Throwable e) {
                logger.warn(e);
            }
        } else {
            logger.trace("Using replyTo from message JMSReplyTo: " + replyTo);
        }
        if (replyTo == null) {
            throw new EJBException("no replyTo Destination");
        }
        final TextMessage tm = (TextMessage) message;
        final String reply = tm.getText() + "processed by: " + hashCode();
        try (JMSContext context = cf.createContext()) {
            context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
        }
    } catch (Exception e) {
        logger.error(e);
        throw new EJBException(e);
    }
}
Also used : Destination(javax.jms.Destination) EJBException(javax.ejb.EJBException) TextMessage(javax.jms.TextMessage) JMSContext(javax.jms.JMSContext) EJBException(javax.ejb.EJBException) NamingException(javax.naming.NamingException)

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