Search in sources :

Example 61 with QueueConnection

use of javax.jms.QueueConnection in project core by weld.

the class EJBTest method testMdbUsable.

@Test
public void testMdbUsable(Control control) throws Exception {
    InitialContext ctx = new InitialContext();
    QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
    QueueConnection connection = factory.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = (Queue) ctx.lookup(WildFly8EEResourceManager.TEST_QUEUE_DESTINATION);
    QueueSender sender = session.createSender(queue);
    sender.send(session.createTextMessage(MESSAGE));
    control.getLatch().await();
    Assert.assertTrue(control.isMessageDelivered());
    Assert.assertTrue(control.isContextSet());
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueConnectionFactory(javax.jms.QueueConnectionFactory) QueueSender(javax.jms.QueueSender) Queue(javax.jms.Queue) InitialContext(javax.naming.InitialContext) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 62 with QueueConnection

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

the class MDBEJBRuntimeNameTestsCase method testMDB.

@Test
@InSequence(1)
public void testMDB() throws Exception {
    final QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup("java:/jms/RemoteConnectionFactory");
    final QueueConnection connection = factory.createQueueConnection("guest", "guest");
    try {
        connection.start();
        final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        final Queue replyDestination = session.createTemporaryQueue();
        final String requestMessage = "test";
        final Message message = session.createTextMessage(requestMessage);
        message.setJMSReplyTo(replyDestination);
        final Destination destination = (Destination) context.lookup(Constants.QUEUE_JNDI_NAME);
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
        producer.close();
        // wait for a reply
        final QueueReceiver receiver = session.createReceiver(replyDestination);
        final Message reply = receiver.receive(TimeoutUtil.adjust(1000));
        assertNotNull("Did not receive a reply on the reply queue. Perhaps the original (request) message didn't make it to the MDB?", reply);
        final String result = ((TextMessage) reply).getText();
        assertEquals("Unexpected reply messsage", Constants.REPLY_MESSAGE_PREFIX + requestMessage, result);
    } finally {
        if (connection != null) {
            // just closing the connection will close the session and other related resources (@see javax.jms.Connection)
            safeClose(connection);
        }
    }
}
Also used : Destination(javax.jms.Destination) QueueConnection(javax.jms.QueueConnection) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) QueueReceiver(javax.jms.QueueReceiver) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 63 with QueueConnection

use of javax.jms.QueueConnection in project page-factory-2 by sbtqa.

the class ActiveMqTest method createConnection.

private Jms<TextMessage> createConnection() {
    QueueConnection queueConnection = null;
    try {
        ActiveMQConnectionFactory mqCF = new ActiveMQConnectionFactory(AMQ_BROKER_URL);
        queueConnection = mqCF.createQueueConnection();
    } catch (JMSException ex) {
        LOG.error("", ex);
    }
    Properties connProps = new Properties();
    connProps.put(MqFactory.MQ_TYPE, "activeMq");
    connProps.put(MqFactory.JMS_CONNECTION, queueConnection);
    mQueueConnection = queueConnection;
    return MqFactory.getMq(connProps);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) QueueConnection(javax.jms.QueueConnection) JMSException(javax.jms.JMSException) Properties(java.util.Properties)

Example 64 with QueueConnection

use of javax.jms.QueueConnection in project brave by openzipkin.

the class JmsTracingTest method queueConnection_doesntDoubleWrap.

@Test
public void queueConnection_doesntDoubleWrap() {
    QueueConnection wrapped = jmsTracing.queueConnection(mock(QueueConnection.class));
    assertThat(jmsTracing.queueConnection(wrapped)).isSameAs(wrapped);
}
Also used : XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) Test(org.junit.Test)

Example 65 with QueueConnection

use of javax.jms.QueueConnection in project brave by openzipkin.

the class TracingConnection method createConnectionConsumer.

@Override
public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException {
    checkQueueConnection();
    ConnectionConsumer cc = ((QueueConnection) delegate).createConnectionConsumer(queue, messageSelector, sessionPool, maxMessages);
    return TracingConnectionConsumer.create(cc, jmsTracing);
}
Also used : ConnectionConsumer(javax.jms.ConnectionConsumer) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection)

Aggregations

QueueConnection (javax.jms.QueueConnection)77 QueueSession (javax.jms.QueueSession)53 Test (org.junit.Test)41 TextMessage (javax.jms.TextMessage)36 Queue (javax.jms.Queue)33 Message (javax.jms.Message)26 MessageProducer (javax.jms.MessageProducer)20 QueueConnectionFactory (javax.jms.QueueConnectionFactory)20 Session (javax.jms.Session)17 JMSException (javax.jms.JMSException)16 InitialContext (javax.naming.InitialContext)15 QueueSender (javax.jms.QueueSender)14 XAQueueConnection (javax.jms.XAQueueConnection)14 ActiveMQRAConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory)14 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)14 ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)14 QueueReceiver (javax.jms.QueueReceiver)13 MessageConsumer (javax.jms.MessageConsumer)12 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)6