use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class CreateLotsOfTemporaryQueuesTest method testCreateLotsOfTemporaryQueues.
public void testCreateLotsOfTemporaryQueues() throws Exception {
LOG.info("Creating " + numberToCreate + " temporary queue(s)");
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
for (int i = 0; i < numberToCreate; i++) {
if (i % 1000 == 0) {
LOG.info("attempt " + i);
}
TemporaryQueue temporaryQueue = session.createTemporaryQueue();
temporaryQueue.delete();
Thread.sleep(sleep);
}
LOG.info("Created " + numberToCreate + " temporary queue(s)");
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class AdvisoryOpenWireTest method testTempQueueLeakManyConnections.
@Test
public void testTempQueueLeakManyConnections() throws Exception {
final Connection[] connections = new Connection[20];
try {
for (int i = 0; i < connections.length; i++) {
connections[i] = factory.createConnection();
connections[i].start();
}
Session session = connections[0].createSession(false, Session.AUTO_ACKNOWLEDGE);
for (int i = 0; i < connections.length; i++) {
TemporaryQueue temporaryQueue = session.createTemporaryQueue();
temporaryQueue.delete();
}
Object[] addressResources = server.getManagementService().getResources(AddressControl.class);
for (Object addressResource : addressResources) {
if (((AddressControl) addressResource).getAddress().equals("ActiveMQ.Advisory.TempQueue")) {
AddressControl addressControl = (AddressControl) addressResource;
Wait.waitFor(() -> addressControl.getMessageCount() == 0);
assertNotNull("addressControl for temp advisory", addressControl);
Wait.assertEquals(0, addressControl::getMessageCount);
}
}
// sleep a bit to allow message count to go down.
} finally {
for (Connection conn : connections) {
if (conn != null) {
conn.close();
}
}
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class AdvisoryOpenWireTest method testTempQueueLeak.
@Test
public void testTempQueueLeak() throws Exception {
Connection connection = null;
try {
connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue temporaryQueue = session.createTemporaryQueue();
temporaryQueue.delete();
Object[] queueResources = server.getManagementService().getResources(QueueControl.class);
for (Object queueResource : queueResources) {
if (((QueueControl) queueResource).getAddress().equals("ActiveMQ.Advisory.TempQueue")) {
QueueControl queueControl = (QueueControl) queueResource;
Wait.waitFor(() -> queueControl.getMessageCount() == 0);
assertNotNull("addressControl for temp advisory", queueControl);
Wait.assertEquals(0, queueControl::getMessageCount);
Wait.assertEquals(2, queueControl::getMessagesAdded);
}
}
} finally {
if (connection != null) {
connection.close();
}
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class SimpleOpenWireTest method testTempQueueDelete.
@Test
public void testTempQueueDelete() throws Exception {
connection.start();
QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = queueSession.createTemporaryQueue();
ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
try {
QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = newQueueSession.createSender(tempQueue);
Message msg = queueSession.createMessage();
queueSender.send(msg);
try {
QueueReceiver consumer = newQueueSession.createReceiver(tempQueue);
fail("should have gotten exception but got consumer: " + consumer);
} catch (JMSException ex) {
// correct
}
connection.close();
try {
Message newMsg = newQueueSession.createMessage();
queueSender.send(newMsg);
} catch (JMSException e) {
// ok
}
} finally {
newConn.close();
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class SimpleRequestServer method main.
public static void main(final String[] args) throws Exception {
final Map<String, TextMessage> requestMap = new HashMap<>();
Connection connection = null;
InitialContext initialContext = null;
try {
// Step 1. Start the request server
SimpleRequestServer server = new SimpleRequestServer();
server.start();
// Step 2. Create an initial context to perform the JNDI lookup.
initialContext = new InitialContext();
// Step 3. Lookup the queue for sending the request message
Queue requestQueue = (Queue) initialContext.lookup("queue/exampleQueue");
// Step 4. Lookup for the Connection Factory
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
// Step 5. Create a JMS Connection
connection = cf.createConnection();
// Step 6. Start the connection.
connection.start();
// Step 7. Create a JMS Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Step 8. Create a JMS Message Producer to send request message
MessageProducer producer = session.createProducer(requestQueue);
// Step 9. Create a temporary queue used to send reply message
TemporaryQueue replyQueue = session.createTemporaryQueue();
// Step 10. Create consumer to receive reply message
MessageConsumer replyConsumer = session.createConsumer(replyQueue);
// Step 11. Create a request Text Message
TextMessage requestMsg = session.createTextMessage("A request message");
// Step 12. Set the ReplyTo header so that the request receiver knows where to send the reply.
requestMsg.setJMSReplyTo(replyQueue);
// Step 13. Sent the request message
producer.send(requestMsg);
System.out.println("Request message sent.");
// Step 14. Put the request message to the map. Later we can use it to
// check out which request message a reply message is for. Here we use the MessageID as the
// correlation id (JMSCorrelationID). You don't have to use it though. You can use some arbitrary string for
// example.
requestMap.put(requestMsg.getJMSMessageID(), requestMsg);
// Step 15. Receive the reply message.
TextMessage replyMessageReceived = (TextMessage) replyConsumer.receive();
System.out.println("Received reply: " + replyMessageReceived.getText());
System.out.println("CorrelatedId: " + replyMessageReceived.getJMSCorrelationID());
// Step 16. Check out which request message is this reply message sent for.
// Here we just have one request message for illustrative purpose. In real world there may be many requests and
// many replies.
TextMessage matchedMessage = requestMap.get(replyMessageReceived.getJMSCorrelationID());
System.out.println("We found matched request: " + matchedMessage.getText());
// Step 17. close the consumer.
replyConsumer.close();
// Step 18. Delete the temporary queue
replyQueue.delete();
// Step 19. Shutdown the request server
server.shutdown();
} finally {
// Step 20. Be sure to close our JMS resources!
if (connection != null) {
connection.close();
}
// Step 21. Also close the initialContext!
if (initialContext != null) {
initialContext.close();
}
}
}
Aggregations