Search in sources :

Example 41 with JMSContext

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

the class ContainerManagedTransactionNotSupportedTestCase method doSetRollbackOnlyInContainerManagedTransactionNotSupportedMDBThrowsIllegalStateException.

private void doSetRollbackOnlyInContainerManagedTransactionNotSupportedMDBThrowsIllegalStateException(Destination destination) throws Exception {
    try (JMSContext context = cf.createContext()) {
        TemporaryQueue replyTo = context.createTemporaryQueue();
        String text = UUID.randomUUID().toString();
        TextMessage message = context.createTextMessage(text);
        message.setJMSReplyTo(replyTo);
        context.createProducer().send(destination, message);
        Message reply = context.createConsumer(replyTo).receive(adjust(5000));
        assertNotNull(reply);
        assertEquals(message.getJMSMessageID(), reply.getJMSCorrelationID());
        assertTrue("messageDrivenContext.setRollbackOnly() did not throw the expected IllegalStateException", reply.getBooleanProperty(EXCEPTION_PROP_NAME));
    }
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage)

Example 42 with JMSContext

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

the class SimpleMDB method onMessage.

@Override
public void onMessage(Message message) {
    logger.trace("Received message: " + message);
    try {
        final Destination replyTo = message.getJMSReplyTo();
        if (replyTo != null) {
            logger.trace("Replying to " + replyTo);
            try (JMSContext context = factory.createContext()) {
                String reply = (messageDrivenContext != null) ? SUCCESS_REPLY : FAILURE_REPLY;
                context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
            }
        }
    } catch (JMSException jmse) {
        throw new RuntimeException(jmse);
    }
}
Also used : Destination(javax.jms.Destination) JMSException(javax.jms.JMSException) JMSContext(javax.jms.JMSContext)

Example 43 with JMSContext

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

the class JMSHelper method assertSendAndReceiveTextMessage.

public static void assertSendAndReceiveTextMessage(ConnectionFactory cf, Destination destination, String text) throws JMSException {
    try (JMSContext context = cf.createContext(AUTO_ACKNOWLEDGE)) {
        TemporaryQueue replyTo = context.createTemporaryQueue();
        context.createProducer().setJMSReplyTo(replyTo).send(destination, text);
        String replyText = context.createConsumer(replyTo).receiveBody(String.class, TimeoutUtil.adjust(5000));
        assertEquals(text, replyText);
    }
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext)

Example 44 with JMSContext

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

the class CriticalAnalyzerTestCase method testCriticalAnalyzer.

/**
 * Set the critical analyzer to SHUTDOWN strategy.
 * Use the byteman script to simulate a slow journal that would make the critical analyzer to activate.
 * Check that the critical analyzer was started and created the expected log traces.
 * Check that the broker has been stopped.
 * @throws Exception
 */
@Test
public void testCriticalAnalyzer() throws Exception {
    if (!container.isStarted(DEFAULT_FULL_JBOSSAS)) {
        container.start(DEFAULT_FULL_JBOSSAS);
    }
    InitialContext remoteContext = createJNDIContext();
    managementClient = createManagementClient();
    ConnectionFactory cf = (ConnectionFactory) remoteContext.lookup("jms/RemoteConnectionFactory");
    Queue queue = (Queue) remoteContext.lookup("queue/critical");
    deployRules();
    try (JMSContext context = cf.createContext("guest", "guest", JMSContext.AUTO_ACKNOWLEDGE)) {
        JMSProducer producer = context.createProducer();
        for (int i = 0; i < 20; i++) {
            TextMessage message = context.createTextMessage(RandomStringUtils.randomAlphabetic(10));
            producer.send(queue, message);
        }
        Assert.fail("Critical analyzer should have kicked in");
    } catch (javax.jms.JMSRuntimeException ex) {
        Assert.assertTrue("Log should contains ActiveMQ connection failure error log message: [AMQ219016]", ex.getMessage().contains("AMQ219016"));
        Assert.assertTrue("Log should contains ActiveMQ critical measure ", LoggingUtil.hasLogMessage(managementClient, "artemis-log", "", (line) -> (line.contains("[org.apache.activemq.artemis.utils.critical.CriticalMeasure]"))));
        Assert.assertTrue("Log should contains ActiveMQ AMQ224080 : critical analyzer is stopping the broker", LoggingUtil.hasLogMessage(managementClient, "artemis-log", "", (line) -> (line.contains("AMQ224080"))));
        Assert.assertTrue("Log should contains ActiveMQ AMQ222199 : Thread dump ", LoggingUtil.hasLogMessage(managementClient, "artemis-log", "", (line) -> (line.contains("AMQ222199"))));
    }
    remoteContext.close();
    assertFalse(isBrokerRunning());
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) JMSProducer(javax.jms.JMSProducer) Queue(javax.jms.Queue) InitialContext(javax.naming.InitialContext) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 45 with JMSContext

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

the class AbstractMessagingHATestCase method sendMessage.

protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException {
    log.trace("Looking up for the RemoteConnectionFactory with " + ctx);
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    log.trace("Looking up for the destination with " + ctx);
    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)

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