use of javax.jms.ExceptionListener in project activemq-artemis by apache.
the class TopicRedeliverTest method testNoExceptionOnRedeliveryAckWithSimpleTopicConsumer.
public void testNoExceptionOnRedeliveryAckWithSimpleTopicConsumer() throws Exception {
Destination destination = createDestination(getClass().getName());
Connection connection = createConnection();
final AtomicBoolean gotException = new AtomicBoolean();
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
LOG.error("unexpected ex:" + exception);
gotException.set(true);
}
});
connection.setClientID(idGen.generateId());
connection.start();
Session consumerSession = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
MessageConsumer consumer = null;
if (topic) {
consumer = consumerSession.createConsumer(destination);
} else {
consumer = consumerSession.createConsumer(destination);
}
Session producerSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = producerSession.createProducer(destination);
producer.setDeliveryMode(deliveryMode);
TextMessage sentMsg = producerSession.createTextMessage();
sentMsg.setText("msg1");
producer.send(sentMsg);
producerSession.commit();
Message recMsg = consumer.receive(RECEIVE_TIMEOUT);
assertFalse(recMsg.getJMSRedelivered());
recMsg = consumer.receive(RECEIVE_TIMEOUT);
consumerSession.rollback();
recMsg = consumer.receive(RECEIVE_TIMEOUT);
assertTrue(recMsg.getJMSRedelivered());
consumerSession.rollback();
recMsg = consumer.receive(RECEIVE_TIMEOUT);
assertTrue(recMsg.getJMSRedelivered());
consumerSession.commit();
assertTrue(recMsg.equals(sentMsg));
assertTrue(recMsg.getJMSRedelivered());
connection.close();
assertFalse("no exception", gotException.get());
}
use of javax.jms.ExceptionListener in project vcell by virtualcell.
the class ConsumerContextJms method init.
public void init() throws JMSException {
boolean bTransacted = true;
int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
try {
this.jmsConnection = vcMessagingServiceJms.createConnectionFactory().createConnection();
this.jmsConnection.setExceptionListener(new ExceptionListener() {
public void onException(JMSException arg0) {
ConsumerContextJms.this.onException(arg0);
}
});
this.jmsConnection.start();
this.jmsSession = this.jmsConnection.createSession(bTransacted, acknowledgeMode);
this.jmsMessageConsumer = this.vcMessagingServiceJms.createConsumer(this.jmsSession, vcConsumer.getVCDestination(), vcConsumer.getSelector(), vcConsumer.getPrefetchLimit());
} catch (JMSException | VCMessagingException e) {
e.printStackTrace(System.out);
onException(e);
}
}
use of javax.jms.ExceptionListener in project cxf by apache.
the class JMSDestination method createTargetDestinationListener.
private JMSListenerContainer createTargetDestinationListener() {
Session session = null;
try {
// NOPMD - UseTryWithResources
ExceptionListener exListener = new ExceptionListener() {
private boolean restartTriggered;
public synchronized void onException(JMSException exception) {
if (!shutdown && !restartTriggered) {
LOG.log(Level.WARNING, "Exception on JMS connection. Trying to reconnect", exception);
new Thread(() -> restartConnection()).start();
restartTriggered = true;
}
}
};
PollingMessageListenerContainer container;
if (!jmsConfig.isOneSessionPerConnection()) {
connection = JMSFactory.createConnection(jmsConfig);
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = jmsConfig.getTargetDestination(session);
container = new PollingMessageListenerContainer(connection, destination, this, exListener);
} else {
container = new PollingMessageListenerContainer(jmsConfig, false, this, exListener);
}
container.setConcurrentConsumers(jmsConfig.getConcurrentConsumers());
container.setTransactionManager(jmsConfig.getTransactionManager());
container.setMessageSelector(jmsConfig.getMessageSelector());
container.setTransacted(jmsConfig.isSessionTransacted());
container.setDurableSubscriptionName(jmsConfig.getDurableSubscriptionName());
container.setPubSubNoLocal(jmsConfig.isPubSubNoLocal());
Object executor = bus.getProperty(JMSFactory.JMS_DESTINATION_EXECUTOR);
if (executor instanceof Executor) {
container.setExecutor((Executor) executor);
}
container.setJndiEnvironment(jmsConfig.getJndiEnvironment());
container.start();
suspendedContinuations.setListenerContainer(container);
if (!jmsConfig.isOneSessionPerConnection()) {
connection.start();
}
return container;
} catch (JMSException e) {
ResourceCloser.close(connection);
this.connection = null;
throw JMSUtil.convertJmsException(e);
} finally {
ResourceCloser.close(session);
}
}
use of javax.jms.ExceptionListener in project cxf by apache.
the class MessageListenerTest method testWithJTA.
@Test
public void testWithJTA() throws JMSException, XAException, InterruptedException {
TransactionManager transactionManager = new GeronimoTransactionManager();
Connection connection = createXAConnection("brokerJTA", transactionManager);
Queue dest = JMSUtil.createQueue(connection, "test");
MessageListener listenerHandler = new TestMessageListener();
ExceptionListener exListener = new TestExceptionListener();
PollingMessageListenerContainer container = new PollingMessageListenerContainer(connection, dest, listenerHandler, exListener);
container.setTransacted(false);
container.setAcknowledgeMode(Session.SESSION_TRANSACTED);
container.setTransactionManager(transactionManager);
container.start();
testTransactionalBehaviour(connection, dest);
container.stop();
connection.close();
}
use of javax.jms.ExceptionListener in project rabbitmq-jms-client by rabbitmq.
the class ConnectionCloseIT method testCloseDuringReceiveWithExceptionListener.
@Test
public void testCloseDuringReceiveWithExceptionListener() throws Exception {
ExceptionListener eListener = new ExceptionListener() {
@Override
public void onException(JMSException exception) {
atomBool.set(true);
atomJMSExceptionRef.set(exception);
}
};
topicConn.setExceptionListener(eListener);
topicConn.start();
TopicSession topicSession = topicConn.createTopicSession(true, Session.DUPS_OK_ACKNOWLEDGE);
Topic topicDestination = topicSession.createTopic(TOPIC_NAME);
MessageConsumer messageConsumer = topicSession.createConsumer(topicDestination);
Completion receiveCompletion = new Completion();
Thread receiver = new DelayedReceive(ZERO_SECONDS, messageConsumer, receiveCompletion);
Thread closer = new DelayedClose(ONE_SECOND, topicConn);
receiver.start();
closer.start();
try {
receiveCompletion.waitUntilComplete(FIVE_SECONDS, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
fail("Timeout before receive returns!");
}
if (atomBool.get()) {
fail(String.format("ExceptionListener driven with exception %s", atomJMSExceptionRef.get()));
}
}
Aggregations