Search in sources :

Example 26 with TemporaryQueue

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

the class TwoSecureBrokerRequestReplyTest method testRequestReply.

public void testRequestReply() throws Exception {
    ActiveMQQueue requestReplyDest = new ActiveMQQueue("RequestReply");
    startAllBrokers();
    waitForBridgeFormation();
    waitForMinTopicRegionConsumerCount("sender", 1);
    waitForMinTopicRegionConsumerCount("receiver", 1);
    ConnectionFactory factory = getConnectionFactory("sender");
    ActiveMQConnection conn = (ActiveMQConnection) factory.createConnection("system", "manager");
    conn.setWatchTopicAdvisories(false);
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ConnectionFactory replyFactory = getConnectionFactory("receiver");
    for (int i = 0; i < 2000; i++) {
        TemporaryQueue tempDest = session.createTemporaryQueue();
        MessageProducer producer = session.createProducer(requestReplyDest);
        javax.jms.Message message = session.createTextMessage("req-" + i);
        message.setJMSReplyTo(tempDest);
        ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(tempDest);
        producer.send(message);
        ActiveMQConnection replyConnection = (ActiveMQConnection) replyFactory.createConnection("system", "manager");
        replyConnection.setWatchTopicAdvisories(false);
        replyConnection.start();
        Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQMessageConsumer replyConsumer = (ActiveMQMessageConsumer) replySession.createConsumer(requestReplyDest);
        javax.jms.Message msg = replyConsumer.receive(10000);
        assertNotNull("request message not null: " + i, msg);
        MessageProducer replyProducer = replySession.createProducer(msg.getJMSReplyTo());
        replyProducer.send(session.createTextMessage("reply-" + i));
        replyConnection.close();
        javax.jms.Message reply = consumer.receive(10000);
        assertNotNull("reply message : " + i + ", to: " + tempDest + ", by consumer:" + consumer.getConsumerId(), reply);
        consumer.close();
        tempDest.delete();
        LOG.info("message #" + i + " processed");
    }
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 27 with TemporaryQueue

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

the class TwoBrokerTempQueueAdvisoryTest method testSendToRemovedTemp.

public void testSendToRemovedTemp() throws Exception {
    ActiveMQQueue requestReplyDest = new ActiveMQQueue("RequestReply");
    NetworkConnector nc = bridgeBrokers("BrokerA", "BrokerB");
    if (useDuplex) {
        nc.setDuplex(true);
    } else {
        bridgeBrokers("BrokerB", "BrokerA");
    }
    // way
    if (!useDuplex) {
        brokers.get("BrokerB").broker.setAllowTempAutoCreationOnSend(true);
    }
    TransportConnector forClient = brokers.get("BrokerA").broker.addConnector("tcp://localhost:0");
    startAllBrokers();
    waitForBridgeFormation();
    waitForMinTopicRegionConsumerCount("BrokerB", 1);
    waitForMinTopicRegionConsumerCount("BrokerA", 1);
    ConnectionFactory factory = new ActiveMQConnectionFactory(forClient.getConnectUri());
    ActiveMQConnection conn = (ActiveMQConnection) factory.createConnection();
    conn.setWatchTopicAdvisories(false);
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ConnectionFactory replyFactory = getConnectionFactory("BrokerB");
    for (int i = 0; i < 500; i++) {
        TemporaryQueue tempDest = session.createTemporaryQueue();
        MessageProducer producer = session.createProducer(requestReplyDest);
        javax.jms.Message message = session.createTextMessage("req-" + i);
        message.setJMSReplyTo(tempDest);
        ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(tempDest);
        producer.send(message);
        ActiveMQConnection replyConnection = (ActiveMQConnection) replyFactory.createConnection();
        replyConnection.setWatchTopicAdvisories(false);
        replyConnection.start();
        Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQMessageConsumer replyConsumer = (ActiveMQMessageConsumer) replySession.createConsumer(requestReplyDest);
        javax.jms.Message msg = replyConsumer.receive(10000);
        assertNotNull("request message not null: " + i, msg);
        MessageProducer replyProducer = replySession.createProducer(msg.getJMSReplyTo());
        replyProducer.send(session.createTextMessage("reply-" + i));
        replyConnection.close();
        javax.jms.Message reply = consumer.receive(10000);
        assertNotNull("reply message : " + i + ", to: " + tempDest + ", by consumer:" + consumer.getConsumerId(), reply);
        consumer.close();
        tempDest.delete();
    }
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TransportConnector(org.apache.activemq.broker.TransportConnector) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) NetworkConnector(org.apache.activemq.network.NetworkConnector) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 28 with TemporaryQueue

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

the class MessageHeaderTest method testJMSReplyTo_2.

/**
 * Test that if the JMS ReplyTo header field has been set as a <code>TemporaryQueue</code>,
 * it will be rightly get also as a <code>TemporaryQueue</code>
 * (and not only as a <code>Queue</code>).
 */
@Test
public void testJMSReplyTo_2() {
    try {
        TemporaryQueue tempQueue = senderSession.createTemporaryQueue();
        Message message = senderSession.createMessage();
        message.setJMSReplyTo(tempQueue);
        sender.send(message);
        Message msg = receiver.receive(TestConfig.TIMEOUT);
        Destination dest = msg.getJMSReplyTo();
        Assert.assertTrue("JMS ReplyTo header field should be a TemporaryQueue", dest instanceof TemporaryQueue);
        Queue replyTo = (Queue) dest;
        Assert.assertEquals("JMS ReplyTo header field should be equals to the temporary queue", replyTo.getQueueName(), tempQueue.getQueueName());
    } catch (JMSException e) {
        fail(e);
    }
}
Also used : Destination(javax.jms.Destination) Message(javax.jms.Message) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) Test(org.junit.Test)

Example 29 with TemporaryQueue

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

the class TemporaryDestinationTest method testTemporaryQueueShouldNotBeInJNDI.

@Test
public void testTemporaryQueueShouldNotBeInJNDI() throws Exception {
    Connection producerConnection = createConnection();
    Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
    String queueName = tempQueue.getQueueName();
    try {
        ic.lookup("/queue/" + queueName);
        ProxyAssertSupport.fail("The temporary queue should not be bound to JNDI");
    } catch (NamingException e) {
    // Expected
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) NamingException(javax.naming.NamingException) Session(javax.jms.Session) Test(org.junit.Test)

Example 30 with TemporaryQueue

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

the class TemporaryDestinationTest method testCanNotCreateConsumerFromAnotherConnectionForTemporaryQueue.

/**
 * https://jira.jboss.org/jira/browse/JBMESSAGING-1566
 */
@Test
public void testCanNotCreateConsumerFromAnotherConnectionForTemporaryQueue() throws Exception {
    Connection conn = createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = sess.createTemporaryQueue();
    Connection anotherConn = createConnection();
    Session sessFromAnotherConn = anotherConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
        sessFromAnotherConn.createConsumer(tempQueue);
        ProxyAssertSupport.fail("Only temporary destination's own connection is allowed to create MessageConsumers for them.");
    } catch (JMSException e) {
    }
    conn.close();
    anotherConn.close();
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

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