Search in sources :

Example 96 with JMSContext

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

the class VaultedInjectedJMSContextTestCase method sendMessage.

@Test
public void sendMessage() throws JMSException {
    String text = UUID.randomUUID().toString();
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue tempQueue = context.createTemporaryQueue();
        producerBean.sendToDestination(tempQueue, text);
        JMSConsumer consumer = context.createConsumer(tempQueue);
        String reply = consumer.receiveBody(String.class, adjust(2000));
        assertEquals(text, reply);
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 97 with JMSContext

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

the class MessagingBean method checkDeploymendDescriptorBasedDefinitionsWithVaultedAttributes.

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

Example 98 with JMSContext

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

the class MessagingBean method checkInjectedResources.

public void checkInjectedResources() {
    assertNotNull(queue1);
    assertNotNull(queue2);
    assertNotNull(queue3);
    assertNotNull(queue4);
    assertNotNull(topic1);
    assertNotNull(topic2);
    assertNotNull(factory1);
    assertNotNull(factory2);
    assertNotNull(factory3);
    assertNotNull(factory4);
    assertNotNull(factory5);
    assertNotNull(factory6);
    JMSContext context = factory3.createContext("guest", "guest", AUTO_ACKNOWLEDGE);
    JMSConsumer consumer = context.createConsumer(queue4);
    assertNotNull(consumer);
    consumer.close();
}
Also used : JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext)

Example 99 with JMSContext

use of javax.jms.JMSContext in project tomee by apache.

the class JMS2AMQTest method receive.

@Test
public void receive() throws InterruptedException {
    final String text = TEXT + "2";
    final AtomicReference<Throwable> error = new AtomicReference<>();
    final CountDownLatch ready = new CountDownLatch(1);
    final CountDownLatch over = new CountDownLatch(1);
    new Thread() {

        @Override
        public void run() {
            {
                setName(JMS2AMQTest.class.getName() + ".receive#receiver");
            }
            try (final JMSContext context = cf.createContext()) {
                try (final JMSConsumer consumer = context.createConsumer(destination2)) {
                    ready.countDown();
                    assertEquals(text, consumer.receiveBody(String.class, TimeUnit.MINUTES.toMillis(1)));
                }
            } catch (final Throwable ex) {
                error.set(ex);
            } finally {
                over.countDown();
            }
        }
    }.start();
    ready.await(1, TimeUnit.MINUTES);
    // just to ensure we called receive already
    sleep(150);
    // now send the message
    try (final JMSContext context = cf.createContext()) {
        context.createProducer().send(destination2, text);
    } catch (final JMSRuntimeException ex) {
        fail(ex.getMessage());
    }
    over.await(1, TimeUnit.MINUTES);
    // ensure we got the message and no exception
    final Throwable exception = error.get();
    if (exception != null) {
        exception.printStackTrace();
    }
    assertNull(exception == null ? "ok" : exception.getMessage(), exception);
}
Also used : JMSConsumer(javax.jms.JMSConsumer) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 100 with JMSContext

use of javax.jms.JMSContext in project tomee by apache.

the class JMS2AMQTest method serialize.

@Test
public void serialize() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
    final JMSContext c = SerializationUtils.deserialize(SerializationUtils.serialize(Serializable.class.cast(context)));
    ut.begin();
    session.ok();
    ut.commit();
}
Also used : JMSContext(javax.jms.JMSContext) 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