use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method doTestMultiChannelListResolutionByMessage.
private void doTestMultiChannelListResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelResolver.addChannel("foo-channel", fooChannel);
channelResolver.addChannel("bar-channel", barChannel);
router.setChannelResolver(channelResolver);
Message<String> fooMessage = new GenericMessage<String>("foo");
Message<String> barMessage = new GenericMessage<String>("bar");
Message<String> badMessage = new GenericMessage<String>("bad");
router.handleMessage(fooMessage);
Message<?> result1a = fooChannel.receive(0);
Message<?> result1b = barChannel.receive(0);
assertNotNull(result1a);
assertEquals("foo", result1a.getPayload());
assertNotNull(result1b);
assertEquals("foo", result1b.getPayload());
router.handleMessage(barMessage);
Message<?> result2a = fooChannel.receive(0);
Message<?> result2b = barChannel.receive(0);
assertNotNull(result2a);
assertEquals("bar", result2a.getPayload());
assertNotNull(result2b);
assertEquals("bar", result2b.getPayload());
try {
router.handleMessage(badMessage);
fail();
} catch (MessageDeliveryException e) {
/* Success */
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method doTestChannelInstanceResolutionByPayload.
private void doTestChannelInstanceResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) {
Message<String> fooMessage = new GenericMessage<String>("foo");
Message<String> barMessage = new GenericMessage<String>("bar");
Message<String> badMessage = new GenericMessage<String>("bad");
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelResolver.addChannel("foo-channel", fooChannel);
channelResolver.addChannel("bar-channel", barChannel);
router.setChannelResolver(channelResolver);
router.handleMessage(fooMessage);
Message<?> result1 = fooChannel.receive(0);
assertNotNull(result1);
assertEquals("foo", result1.getPayload());
router.handleMessage(barMessage);
Message<?> result2 = barChannel.receive(0);
assertNotNull(result2);
assertEquals("bar", result2.getPayload());
try {
router.handleMessage(badMessage);
fail();
} catch (MessageDeliveryException e) {
/* Success */
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class ChannelIntegrationTests method testMessageChannelStatistics.
@Test
public void testMessageChannelStatistics() throws Exception {
requests.send(new GenericMessage<String>("foo"));
String intermediateChannelName = "" + intermediate;
assertEquals(1, messageChannelsMonitor.getChannelSendCount(intermediateChannelName));
double rate = messageChannelsMonitor.getChannelSendRate("" + requests).getMean();
assertTrue("No statistics for requests channel", rate >= 0);
rate = messageChannelsMonitor.getChannelSendRate(intermediateChannelName).getMean();
assertTrue("No statistics for intermediate channel", rate >= 0);
assertNotNull(intermediate.receive(100L));
assertEquals(1, messageChannelsMonitor.getChannelReceiveCount(intermediateChannelName));
requests.send(new GenericMessage<String>("foo"));
try {
requests.send(new GenericMessage<String>("foo"));
} catch (MessageDeliveryException e) {
}
assertEquals(3, messageChannelsMonitor.getChannelSendCount(intermediateChannelName));
assertEquals(1, messageChannelsMonitor.getChannelSendErrorCount(intermediateChannelName));
assertSame(intermediate, messageChannelsMonitor.getChannelMetrics(intermediateChannelName));
MessageHandlerMetrics handlerMetrics = messageChannelsMonitor.getHandlerMetrics("bridge");
assertEquals(3, handlerMetrics.getHandleCount());
assertEquals(1, handlerMetrics.getErrorCount());
assertNotNull(this.sourceChannel.receive(10000));
assertTrue(messageChannelsMonitor.getSourceMessageCount("source") > 0);
assertTrue(messageChannelsMonitor.getSourceMetrics("source").getMessageCount() > 0);
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class UnicastSendingMessageHandler method handleMessageInternal.
@Override
public void handleMessageInternal(Message<?> message) throws MessageHandlingException, MessageDeliveryException {
if (this.acknowledge) {
Assert.state(this.isRunning(), "When 'acknowledge' is enabled, adapter must be running");
startAckThread();
}
CountDownLatch countdownLatch = null;
String messageId = message.getHeaders().getId().toString();
try {
boolean waitForAck = this.waitForAck;
if (waitForAck) {
countdownLatch = new CountDownLatch(this.ackCounter);
this.ackControl.put(messageId, countdownLatch);
}
convertAndSend(message);
if (waitForAck) {
try {
if (!countdownLatch.await(this.ackTimeout, TimeUnit.MILLISECONDS)) {
throw new MessagingException(message, "Failed to receive UDP Ack in " + this.ackTimeout + " millis");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
} catch (MessagingException e) {
throw e;
} catch (Exception e) {
closeSocketIfNeeded();
throw new MessageHandlingException(message, "failed to send UDP packet", e);
} finally {
if (countdownLatch != null) {
this.ackControl.remove(messageId);
}
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class StompMessageHandler method handleMessageInternal.
@Override
protected void handleMessageInternal(final Message<?> message) throws Exception {
try {
connectIfNecessary();
} catch (Exception e) {
throw new MessageDeliveryException(message, "The [" + this + "] could not deliver message.", e);
}
StompSession stompSession = this.stompSession;
StompHeaders stompHeaders = new StompHeaders();
this.headerMapper.fromHeaders(message.getHeaders(), stompHeaders);
if (stompHeaders.getDestination() == null) {
Assert.state(this.destinationExpression != null, "One of 'destination' or 'destinationExpression' must be" + " provided, if message header doesn't supply 'destination' STOMP header.");
String destination = this.destinationExpression.getValue(this.evaluationContext, message, String.class);
stompHeaders.setDestination(destination);
}
final StompSession.Receiptable receiptable = stompSession.send(stompHeaders, message.getPayload());
if (receiptable.getReceiptId() != null) {
final String destination = stompHeaders.getDestination();
final ApplicationEventPublisher applicationEventPublisher = this.applicationEventPublisher;
if (applicationEventPublisher != null) {
receiptable.addReceiptTask(() -> {
StompReceiptEvent event = new StompReceiptEvent(StompMessageHandler.this, destination, receiptable.getReceiptId(), StompCommand.SEND, false);
event.setMessage(message);
applicationEventPublisher.publishEvent(event);
});
}
receiptable.addReceiptLostTask(() -> {
if (applicationEventPublisher != null) {
StompReceiptEvent event = new StompReceiptEvent(StompMessageHandler.this, destination, receiptable.getReceiptId(), StompCommand.SEND, true);
event.setMessage(message);
applicationEventPublisher.publishEvent(event);
} else {
logger.error("The receipt [" + receiptable.getReceiptId() + "] is lost for [" + message + "] on destination [" + destination + "]");
}
});
}
}
Aggregations