use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class BrowserTest method testCreateBrowserOnNullDestination.
@Test
public void testCreateBrowserOnNullDestination() throws Exception {
conn = getConnectionFactory().createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
session.createBrowser(null);
ProxyAssertSupport.fail("should throw exception");
} catch (InvalidDestinationException e) {
// OK
}
}
use of javax.jms.InvalidDestinationException in project perun by CESNET.
the class MessageReceiver method run.
@Override
public void run() {
while (running) {
if (!queueAcquired) {
try {
log.debug("Creating new JMS queue " + queueName);
// Step 1. Directly instantiate the JMS Queue object.
queue = HornetQJMSClient.createQueue(queueName);
// Step 9. Create a JMS Message Consumer
log.debug("Creating JMS consumer");
messageConsumer = session.createConsumer(queue);
queueAcquired = true;
log.debug("Ready to receive messages.");
// messageConsumer.receive(timeout) is a blocking operation!
waitTime = 0;
} catch (InvalidDestinationException e) {
queueAcquired = false;
waitTime = setWaitTime(waitTime);
log.error("Queue doesn't exist yet. We gonna wait a bit ({} s) and try it again.", (waitTime / 1000), e);
// wait for a time mentioned in the error message before try it again
try {
Thread.sleep(waitTime);
} catch (InterruptedException interrupted) {
log.error(interrupted.toString(), interrupted);
}
} catch (JMSException e) {
queueAcquired = false;
waitTime = setWaitTime(waitTime);
log.error("Something went wrong with JMS. We are gonna wait a bit ({} s) and try it again...", (waitTime / 1000), e);
} catch (Exception e) {
queueAcquired = false;
waitTime = setWaitTime(waitTime);
log.error("Can not continue. We gonna wait a bit ({} s) and try it again...", (waitTime / 1000), e);
}
} else {
// Try to send queued messages first
while (!inputMessages.isEmpty()) {
TextMessage message = inputMessages.remove();
try {
messageProducer.send(message, DeliveryMode.PERSISTENT, message.getIntProperty("priority"), 0);
log.trace("Message {} for dispatcher sent.\n", message.getText());
} catch (JMSException e) {
queueAcquired = false;
log.error("Something went wrong with JMS. We are gonna restart and try it again...", e);
// goes back to reinitialize the connection
return;
}
}
// Step 11. Receive the message
TextMessage messageReceived = null;
try {
messageReceived = (TextMessage) messageConsumer.receive(timeout);
if (messageReceived != null) {
final String message = messageReceived.getText();
String messageType = message.split("\\|", 2)[0].trim();
log.debug("RECEIVED MESSAGE:{}, Type:{}", message, messageType);
if (messageType.equalsIgnoreCase("task")) {
try {
taskExecutorMessageProcess.execute(new Runnable() {
@Override
public void run() {
// TODO: Remove in future
log.trace("I am going to call eventProcessor.receiveEvent(\"{}\") " + "in thread: {}", message, Thread.currentThread().getName());
eventProcessor.receiveEvent(message);
}
});
} catch (TaskRejectedException ex) {
log.error("Task was rejected. Message {}", message);
throw ex;
}
} else if (messageType.equalsIgnoreCase("command")) {
// TODO: There is no need to put commandProcessor to
// a separate thread at the moment, however it is
// very likely to be so in a future.
commandProcessor.receiveCommand(message);
} else {
throw new UnknownMessageTypeException("UNKNOWN TYPE[" + messageType + "]");
}
}
waitTime = 0;
} catch (InvalidDestinationException e) {
queueAcquired = false;
waitTime = setWaitTime(waitTime);
log.error("Queue doesn't exist or the connection is broken. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
} catch (JMSException e) {
queueAcquired = false;
waitTime = setWaitTime(waitTime);
log.error("Something went wrong with JMS. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
} catch (Exception e) {
queueAcquired = false;
waitTime = setWaitTime(waitTime);
log.error("Can not continue. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
}
}
if (waitTime > 0) {
if (waitTime > TOO_LONG) {
// gonna be back after trying to reinitialize the connection
return;
}
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
log.error(e.toString(), e);
}
}
}
}
use of javax.jms.InvalidDestinationException in project qpid-broker-j by apache.
the class MessageProducerTest method anonymousSenderSendToUnknownQueue.
@Test
public void anonymousSenderSendToUnknownQueue() throws Exception {
assumeThat("QPID-7818", getProtocol(), is(not(equalTo(Protocol.AMQP_0_10))));
Connection connection = getConnectionBuilder().setSyncPublish(true).build();
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue invalidDestination = session.createQueue("unknown");
try {
MessageProducer sender = session.createProducer(null);
sender.send(invalidDestination, session.createMessage());
fail("Exception not thrown");
} catch (InvalidDestinationException e) {
// PASS
} catch (JMSException e) {
assertThat("Allowed for the Qpid JMS AMQP 0-x client", getProtocol(), is(not(equalTo(Protocol.AMQP_1_0))));
// PASS
}
} finally {
connection.close();
}
}
use of javax.jms.InvalidDestinationException in project qpid-broker-j by apache.
the class DurableSubscribtionTest method unsubscribeTwice.
@Test
public void unsubscribeTwice() throws Exception {
Topic topic = createTopic(getTestName());
Connection connection = getConnection();
String subscriptionName = getTestName() + "_sub";
try {
Session subscriberSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = subscriberSession.createDurableSubscriber(topic, subscriptionName);
MessageProducer publisher = subscriberSession.createProducer(topic);
connection.start();
publisher.send(subscriberSession.createTextMessage("Test"));
subscriberSession.commit();
Message message = subscriber.receive(getReceiveTimeout());
assertTrue("TextMessage should be received", message instanceof TextMessage);
assertEquals("Unexpected message", "Test", ((TextMessage) message).getText());
subscriberSession.commit();
subscriber.close();
subscriberSession.unsubscribe(subscriptionName);
try {
subscriberSession.unsubscribe(subscriptionName);
fail("expected InvalidDestinationException when unsubscribing from unknown subscription");
} catch (InvalidDestinationException e) {
// PASS
} catch (Exception e) {
fail("expected InvalidDestinationException when unsubscribing from unknown subscription, got: " + e);
}
} finally {
connection.close();
}
}
use of javax.jms.InvalidDestinationException in project iaf by ibissource.
the class JMSFacade method send.
public String send(Session session, Destination dest, Message message, boolean ignoreInvalidDestinationException) throws NamingException, JMSException {
try {
if (useJms102()) {
if (dest instanceof Topic) {
return sendByTopic((TopicSession) session, (Topic) dest, message);
} else {
return sendByQueue((QueueSession) session, (Queue) dest, message);
}
} else {
MessageProducer mp = session.createProducer(dest);
mp.send(message);
mp.close();
return message.getJMSMessageID();
}
} catch (InvalidDestinationException e) {
if (ignoreInvalidDestinationException) {
log.warn("queue [" + dest + "] doesn't exist");
return null;
} else {
throw e;
}
}
}
Aggregations