Search in sources :

Example 31 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class JMSReplyToHeaderTest method testJMSDestinationSimple.

// Constants -----------------------------------------------------
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testJMSDestinationSimple() throws Exception {
    Message m = queueProducerSession.createMessage();
    TemporaryQueue tempQ = queueProducerSession.createTemporaryQueue();
    m.setJMSReplyTo(tempQ);
    queueProducer.send(m);
    queueConsumer.receive();
    ProxyAssertSupport.assertEquals(tempQ, m.getJMSReplyTo());
}
Also used : Message(javax.jms.Message) TemporaryQueue(javax.jms.TemporaryQueue) Test(org.junit.Test)

Example 32 with TemporaryQueue

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

the class HelloBean method sendMessage.

/**
 * Helper method to send message to {@link #QUEUE_NAME}.
 */
public static String sendMessage(ConnectionFactory cf) throws Exception {
    Connection connection = null;
    try {
        Queue queue = cf.createContext("guest", "guest").createQueue(QUEUE_NAME);
        connection = cf.createConnection("guest", "guest");
        // we need to start connection for consumer
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer sender = session.createProducer(queue);
        TextMessage message = session.createTextMessage("hello goodbye");
        TemporaryQueue replyQueue = session.createTemporaryQueue();
        message.setJMSReplyTo(replyQueue);
        sender.send(message);
        log.tracef("Message '%s' sent", message);
        // consume message processed by MDB
        MessageConsumer consumer = session.createConsumer(replyQueue);
        TextMessage replyMessage = (TextMessage) consumer.receive(TimeoutUtil.adjust(5000));
        log.tracef("Message '%s' received", replyMessage);
        if (replyMessage == null) {
            return "ReplyMessage is 'null'. No response received from HelloMDB." + " Consult server log for details.";
        }
        return replyMessage.getText();
    } finally {
        try {
            if (connection != null)
                connection.close();
        } catch (JMSException jmse) {
            log.trace("connection close failed", jmse);
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 33 with TemporaryQueue

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

the class GetCallerPrincipalTestCase method testMDBLifecycle.

/**
 * Run this one in the container so it can lookup the queue
 * @throws Exception
 */
@OperateOnDeployment("test")
@Test
public void testMDBLifecycle() throws Exception {
    deployer.deploy("mdb");
    final Callable<Void> callable = () -> {
        ITestResultsSingleton results = this.getResultsSingleton();
        MessageProducer producer = null;
        MessageConsumer consumer = null;
        QueueConnection conn = null;
        Session session = null;
        try {
            QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory");
            Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME);
            conn = qcf.createQueueConnection("guest", "guest");
            conn.start();
            session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
            TemporaryQueue replyQueue = session.createTemporaryQueue();
            TextMessage msg = session.createTextMessage("Hello world");
            msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
            msg.setJMSReplyTo(replyQueue);
            producer = session.createProducer(queue);
            producer.send(msg);
            consumer = session.createConsumer(replyQueue);
            Message replyMsg = consumer.receive(5000);
            Object obj = ((ObjectMessage) replyMsg).getObject();
            log.trace("MDB message get: " + obj);
            Assert.assertEquals(OK + "start", results.getMdb("postconstruct"));
            deployer.undeploy("mdb");
            Assert.assertEquals(OK + "stop", results.getMdb("predestroy"));
        } finally {
            if (consumer != null) {
                consumer.close();
            }
            if (producer != null) {
                producer.close();
            }
            if (session != null) {
                session.close();
            }
            if (conn != null) {
                conn.close();
            }
        }
        return null;
    };
    Util.switchIdentitySCF("user1", "password1", callable);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) InitialContext(javax.naming.InitialContext) QueueConnection(javax.jms.QueueConnection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 34 with TemporaryQueue

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

the class RunAsMDBUnitTestCase method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
    Connection conn = connFactory.createConnection();
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue replyQueue = session.createTemporaryQueue();
    TextMessage msg = session.createTextMessage("Hello world");
    msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    msg.setJMSReplyTo(replyQueue);
    Queue queue = lookup("java:jboss/" + queueName, Queue.class);
    MessageProducer producer = session.createProducer(queue);
    producer.send(msg);
    MessageConsumer consumer = session.createConsumer(replyQueue);
    Message replyMsg = consumer.receive(5000);
    Assert.assertNotNull(replyMsg);
    if (replyMsg instanceof ObjectMessage) {
        Exception e = (Exception) ((ObjectMessage) replyMsg).getObject();
        throw e;
    }
    Assert.assertTrue(replyMsg instanceof TextMessage);
    String actual = ((TextMessage) replyMsg).getText();
    Assert.assertEquals("SUCCESS", actual);
    consumer.close();
    producer.close();
    session.close();
    conn.close();
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ObjectMessage(javax.jms.ObjectMessage) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 35 with TemporaryQueue

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

the class ConnectionHoldingBean method createConnection.

@Override
public void createConnection() throws JMSException {
    // create a consumer on a temp queue to ensure the Jakarta Messaging
    // connection is actually created and started
    context = factory.createContext("guest", "guest");
    TemporaryQueue tempQueue = context.createTemporaryQueue();
    context.createConsumer(tempQueue);
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue)

Aggregations

TemporaryQueue (javax.jms.TemporaryQueue)91 Session (javax.jms.Session)56 Test (org.junit.Test)47 Connection (javax.jms.Connection)45 MessageProducer (javax.jms.MessageProducer)38 MessageConsumer (javax.jms.MessageConsumer)35 Message (javax.jms.Message)27 JMSException (javax.jms.JMSException)25 TextMessage (javax.jms.TextMessage)24 JMSContext (javax.jms.JMSContext)13 BytesMessage (javax.jms.BytesMessage)10 Destination (javax.jms.Destination)8 Queue (javax.jms.Queue)8 ConnectionFactory (javax.jms.ConnectionFactory)7 ObjectMessage (javax.jms.ObjectMessage)7 JMSConsumer (javax.jms.JMSConsumer)6 TemporaryTopic (javax.jms.TemporaryTopic)6 HashMap (java.util.HashMap)5 MapMessage (javax.jms.MapMessage)5 StreamMessage (javax.jms.StreamMessage)5