use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class ActiveMQRASessionFactoryImpl method close.
/**
* Close
*
* @throws JMSException Thrown if an error occurs
*/
@Override
public void close() throws JMSException {
if (ActiveMQRASessionFactoryImpl.trace) {
ActiveMQRALogger.LOGGER.trace("close() " + this);
}
if (closed) {
return;
}
closed = true;
synchronized (sessions) {
for (Iterator<ActiveMQRASession> i = sessions.iterator(); i.hasNext(); ) {
ActiveMQRASession session = i.next();
try {
session.closeSession();
} catch (Throwable t) {
ActiveMQRALogger.LOGGER.trace("Error closing session", t);
}
i.remove();
}
}
synchronized (tempQueues) {
for (Iterator<TemporaryQueue> i = tempQueues.iterator(); i.hasNext(); ) {
TemporaryQueue temp = i.next();
try {
if (ActiveMQRASessionFactoryImpl.trace) {
ActiveMQRALogger.LOGGER.trace("Closing temporary queue " + temp + " for " + this);
}
temp.delete();
} catch (Throwable t) {
ActiveMQRALogger.LOGGER.trace("Error deleting temporary queue", t);
}
i.remove();
}
}
synchronized (tempTopics) {
for (Iterator<TemporaryTopic> i = tempTopics.iterator(); i.hasNext(); ) {
TemporaryTopic temp = i.next();
try {
if (ActiveMQRASessionFactoryImpl.trace) {
ActiveMQRALogger.LOGGER.trace("Closing temporary topic " + temp + " for " + this);
}
temp.delete();
} catch (Throwable t) {
ActiveMQRALogger.LOGGER.trace("Error deleting temporary queue", t);
}
i.remove();
}
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class JmsTempDestinationTest method testDeleteDestinationWithSubscribersFails.
/**
* Test you can't delete a Destination with Active Subscribers
*
* @throws JMSException
*/
@Test
public void testDeleteDestinationWithSubscribersFails() throws JMSException {
Connection connection = factory.createConnection();
connections.add(connection);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue queue = session.createTemporaryQueue();
connection.start();
session.createConsumer(queue);
// now closed.
try {
queue.delete();
Assert.fail("Should fail as Subscribers are active");
} catch (JMSException e) {
Assert.assertTrue("failed to throw an exception", true);
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class JmsTempDestinationTest method testPublishFailsForClosedConnection.
/**
* Make sure you cannot publish to a temp destination that does not exist
* anymore.
*
* @throws JMSException
* @throws InterruptedException
* @throws URISyntaxException
*/
@Test
public void testPublishFailsForClosedConnection() throws Exception {
Connection tempConnection = factory.createConnection();
connections.add(tempConnection);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
Session tempSession = tempConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final TemporaryQueue queue = tempSession.createTemporaryQueue();
final ActiveMQConnection activeMQConnection = (ActiveMQConnection) connection;
Assert.assertTrue("creation advisory received in time with async dispatch", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return activeMQConnection.activeTempDestinations.containsKey(queue);
}
}));
// This message delivery should work since the temp connection is still
// open.
MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = session.createTextMessage("First");
producer.send(message);
// Closing the connection should destroy the temp queue that was
// created.
tempConnection.close();
// Wait a little bit to let the delete take effect.
Thread.sleep(5000);
// now closed.
try {
message = session.createTextMessage("Hello");
producer.send(message);
Assert.fail("Send should fail since temp destination should not exist anymore.");
} catch (JMSException e) {
e.printStackTrace();
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class AdvisoryTempDestinationTests method testNoSlowConsumerAdvisory.
public void testNoSlowConsumerAdvisory() throws Exception {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue queue = s.createTemporaryQueue();
MessageConsumer consumer = s.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
}
});
Topic advisoryTopic = AdvisorySupport.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
// start throwing messages at the consumer
MessageProducer producer = s.createProducer(queue);
for (int i = 0; i < MESSAGE_COUNT; i++) {
BytesMessage m = s.createBytesMessage();
m.writeBytes(new byte[1024]);
producer.send(m);
}
Message msg = advisoryConsumer.receive(1000);
assertNull(msg);
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class AdvisoryTempDestinationTests method testSlowConsumerAdvisory.
public void testSlowConsumerAdvisory() throws Exception {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue queue = s.createTemporaryQueue();
MessageConsumer consumer = s.createConsumer(queue);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
// start throwing messages at the consumer
MessageProducer producer = s.createProducer(queue);
for (int i = 0; i < MESSAGE_COUNT; i++) {
BytesMessage m = s.createBytesMessage();
m.writeBytes(new byte[1024]);
producer.send(m);
}
Message msg = advisoryConsumer.receive(1000);
assertNotNull(msg);
}
Aggregations