Search in sources :

Example 91 with JMSContext

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

the class CriticalAnalyzerTestCase method testCriticalAnalyzerDisabled.

/**
 * Disable the critical analyzer.
 * Use the byteman script to simulate a slow journal that would make the critical analyzer to activate.
 * Check that there is nothing in the logs and that the broker is still running.
 * @throws Exception
 */
@Test
public void testCriticalAnalyzerDisabled() throws Exception {
    if (!container.isStarted(DEFAULT_FULL_JBOSSAS)) {
        container.start(DEFAULT_FULL_JBOSSAS);
    }
    JMSOperations jmsOperations = JMSOperationsProvider.getInstance(managementClient.getControllerClient());
    managementClient.getControllerClient().execute(Operations.createWriteAttributeOperation(jmsOperations.getServerAddress(), "critical-analyzer-enabled", ModelNode.FALSE));
    jmsOperations.close();
    managementClient.close();
    container.stop(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);
        }
    }
    remoteContext.close();
    assertTrue(isBrokerRunning());
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) JMSOperations(org.jboss.as.test.integration.common.jms.JMSOperations) 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 92 with JMSContext

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

the class AbstractMessagingHATestCase method receiveMessage.

protected static void receiveMessage(Context ctx, String destinationLookup, String expectedText) 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");
        JMSConsumer consumer = context.createConsumer(destination)) {
        String text = consumer.receiveBody(String.class, TimeoutUtil.adjust(5000));
        assertNotNull(text);
        assertEquals(expectedText, text);
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext)

Example 93 with JMSContext

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

the class JMSSender method sendMessage.

@TransactionAttribute(NOT_SUPPORTED)
public void sendMessage(String payload) {
    try (JMSContext context = connectionFactory.createContext()) {
        JMSProducer producer = context.createProducer();
        producer.send(queue, payload);
    }
}
Also used : JMSProducer(javax.jms.JMSProducer) JMSContext(javax.jms.JMSContext) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 94 with JMSContext

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

the class InjectedJMSContextTestCase method sendWith_REQUIRED_transaction.

private void sendWith_REQUIRED_transaction(boolean rollback) throws JMSException {
    String text = UUID.randomUUID().toString();
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue tempQueue = context.createTemporaryQueue();
        producerBean.sendToDestination(tempQueue, text, rollback);
        assertMessageIsReceived(tempQueue, context, text, rollback);
    }
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext)

Example 95 with JMSContext

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

the class InjectedJMSContextTestCase method sendAndReceiveFromMDB.

private void sendAndReceiveFromMDB(boolean rollback) throws JMSException {
    String text = "sendAndReceiveFromMDB " + rollback;
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue replyTo = context.createTemporaryQueue();
        context.createProducer().setJMSReplyTo(replyTo).setProperty("rollback", rollback).send(queue, text);
        assertMessageIsReceived(replyTo, context, text, rollback);
    }
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) 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