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");
}
}
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();
}
}
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);
}
}
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
}
}
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();
}
Aggregations