use of org.springframework.jms.JmsException in project opennms by OpenNMS.
the class JmsNorthbounder method forwardAlarms.
/* (non-Javadoc)
* @see org.opennms.netmgt.alarmd.api.support.AbstractNorthbounder#forwardAlarms(java.util.List)
*/
@Override
public void forwardAlarms(List<NorthboundAlarm> alarms) throws NorthbounderException {
for (final NorthboundAlarm alarm : alarms) {
final Integer count = alarm.getCount();
LOG.debug("Does destination {} take only first occurances? {} Is new alarm? Has count of {}.", m_jmsDestination.getName(), m_jmsDestination.isFirstOccurrenceOnly(), count);
if (count > 1 && m_jmsDestination.isFirstOccurrenceOnly()) {
LOG.debug("Skipping because not new alarm.");
continue;
}
LOG.debug("Attempting to send a message to {} of type {}", m_jmsDestination.getJmsDestination(), m_jmsDestination.getDestinationType());
try {
m_template.send(m_jmsDestination.getJmsDestination(), new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
if (m_jmsDestination.isSendAsObjectMessageEnabled()) {
return session.createObjectMessage(alarm);
} else {
return session.createTextMessage(convertAlarmToText(alarm));
}
}
});
LOG.debug("Sent message");
} catch (JmsException e) {
LOG.error("Unable to send alarm to northbound JMS because {}", e.getLocalizedMessage(), e);
}
}
}
use of org.springframework.jms.JmsException in project spring-framework by spring-projects.
the class DefaultMessageListenerContainer method refreshConnectionUntilSuccessful.
/**
* Refresh the underlying Connection, not returning before an attempt has been
* successful. Called in case of a shared Connection as well as without shared
* Connection, so either needs to operate on the shared Connection or on a
* temporary Connection that just gets established for validation purposes.
* <p>The default implementation retries until it successfully established a
* Connection, for as long as this message listener container is running.
* Applies the specified recovery interval between retries.
* @see #setRecoveryInterval
* @see #start()
* @see #stop()
*/
protected void refreshConnectionUntilSuccessful() {
BackOffExecution execution = this.backOff.start();
while (isRunning()) {
try {
if (sharedConnectionEnabled()) {
refreshSharedConnection();
} else {
Connection con = createConnection();
JmsUtils.closeConnection(con);
}
logger.debug("Successfully refreshed JMS Connection");
break;
} catch (Exception ex) {
if (ex instanceof JMSException) {
invokeExceptionListener((JMSException) ex);
}
StringBuilder msg = new StringBuilder();
msg.append("Could not refresh JMS Connection for destination '");
msg.append(getDestinationDescription()).append("' - retrying using ");
msg.append(execution).append(". Cause: ");
msg.append(ex instanceof JMSException ? JmsUtils.buildExceptionMessage((JMSException) ex) : ex.getMessage());
if (logger.isDebugEnabled()) {
logger.error(msg, ex);
} else {
logger.error(msg);
}
}
if (!applyBackOffTime(execution)) {
logger.error("Stopping container for destination '" + getDestinationDescription() + "': back-off policy does not allow for further attempts.");
stop();
}
}
}
use of org.springframework.jms.JmsException in project spring-framework by spring-projects.
the class JmsUtils method buildExceptionMessage.
/**
* Build a descriptive exception message for the given JMSException,
* incorporating a linked exception's message if appropriate.
* @param ex the JMSException to build a message for
* @return the descriptive message String
* @see jakarta.jms.JMSException#getLinkedException()
*/
public static String buildExceptionMessage(JMSException ex) {
String message = ex.getMessage();
Exception linkedEx = ex.getLinkedException();
if (linkedEx != null) {
if (message == null) {
message = linkedEx.toString();
} else {
String linkedMessage = linkedEx.getMessage();
if (linkedMessage != null && !message.contains(linkedMessage)) {
message = message + "; nested exception is " + linkedEx;
}
}
}
return message;
}
use of org.springframework.jms.JmsException in project ORCID-Source by ORCID.
the class HandleFailedMessages method resendFailedElements.
@Scheduled(cron = "${org.orcid.cron.reindex-failed}")
public void resendFailedElements() {
List<RecordStatusEntity> failedElements = manager.getFailedElements(BATCH_SIZE);
List<RecordStatusEntity> elementsToNotify = new ArrayList<RecordStatusEntity>();
for (RecordStatusEntity element : failedElements) {
try {
// Send RetryMessage for 1.2 dump
if (element.getDumpStatus12Api() > 0) {
RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_1_2_API.value());
jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
}
// Send RetryMessage for 2.0 dump
if (element.getDumpStatus20Api() > 0) {
RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_2_0_API.value());
jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
}
// Send RetryMessage for solr indexing
if (element.getSolrStatus20Api() > 0) {
RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.SOLR.value());
jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
}
// Send RetryMessage for 2.0 activities dump
if (element.getDumpStatus20ActivitiesApi() > 0) {
RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API.value());
jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
}
// Should we notify about this element?
if ((element.getDumpStatus12Api() > maxFailuresBeforeNotify) || (element.getDumpStatus20Api() > maxFailuresBeforeNotify) || (element.getSolrStatus20Api() > maxFailuresBeforeNotify) || (element.getDumpStatus20ActivitiesApi() > maxFailuresBeforeNotify)) {
elementsToNotify.add(element);
}
} catch (JmsException e) {
LOGGER.warn("Unable to resend message for " + element.getId());
}
}
// Send summary
if (!elementsToNotify.isEmpty()) {
String message = buildNotificationMessage(elementsToNotify);
sendSystemAlert(message);
}
}
use of org.springframework.jms.JmsException in project spring-integration by spring-projects.
the class JmsOutboundGatewayTests method testReplyContainerRecovery.
@SuppressWarnings("serial")
@Test
public void testReplyContainerRecovery() throws Exception {
JmsOutboundGateway gateway = new JmsOutboundGateway();
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
gateway.setConnectionFactory(connectionFactory);
gateway.setRequestDestinationName("foo");
gateway.setUseReplyContainer(true);
ReplyContainerProperties replyContainerProperties = new ReplyContainerProperties();
final List<Throwable> errors = new ArrayList<Throwable>();
ExecutorService exec = Executors.newFixedThreadPool(10);
ErrorHandlingTaskExecutor errorHandlingTaskExecutor = new ErrorHandlingTaskExecutor(exec, t -> {
errors.add(t);
throw new RuntimeException(t);
});
replyContainerProperties.setTaskExecutor(errorHandlingTaskExecutor);
replyContainerProperties.setRecoveryInterval(100L);
gateway.setReplyContainerProperties(replyContainerProperties);
final Connection connection = mock(Connection.class);
final AtomicInteger connectionAttempts = new AtomicInteger();
doAnswer(invocation -> {
int theCount = connectionAttempts.incrementAndGet();
if (theCount > 1 && theCount < 4) {
throw new JmsException("bar") {
};
}
return connection;
}).when(connectionFactory).createConnection();
Session session = mock(Session.class);
when(connection.createSession(false, 1)).thenReturn(session);
MessageConsumer consumer = mock(MessageConsumer.class);
when(session.createConsumer(any(Destination.class), isNull())).thenReturn(consumer);
when(session.createTemporaryQueue()).thenReturn(mock(TemporaryQueue.class));
final Message message = mock(Message.class);
final AtomicInteger count = new AtomicInteger();
doAnswer(invocation -> {
int theCount = count.incrementAndGet();
if (theCount > 1 && theCount < 4) {
throw new JmsException("foo") {
};
}
if (theCount > 4) {
Thread.sleep(100);
return null;
}
return message;
}).when(consumer).receive(anyLong());
when(message.getJMSCorrelationID()).thenReturn("foo");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.initialize();
beanFactory.registerSingleton("taskScheduler", taskScheduler);
gateway.setBeanFactory(beanFactory);
gateway.afterPropertiesSet();
gateway.start();
try {
int n = 0;
while (n++ < 100 && count.get() < 5) {
Thread.sleep(100);
}
assertTrue(count.get() > 4);
assertEquals(0, errors.size());
} finally {
gateway.stop();
exec.shutdownNow();
}
}
Aggregations