use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method errorMessageSendingRecovererTestsNoThrowable.
@Test
public void errorMessageSendingRecovererTestsNoThrowable() {
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
throw new RuntimeException("fooException");
}
};
QueueChannel errors = new QueueChannel();
RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice();
ErrorMessageSendingRecoverer recoverer = new ErrorMessageSendingRecoverer(errors);
advice.setRecoveryCallback(recoverer);
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(new SimpleRetryPolicy() {
static final long serialVersionUID = -1;
@Override
public boolean canRetry(RetryContext context) {
return false;
}
});
advice.setRetryTemplate(retryTemplate);
advice.setBeanFactory(mock(BeanFactory.class));
advice.afterPropertiesSet();
List<Advice> adviceChain = new ArrayList<Advice>();
adviceChain.add(advice);
handler.setAdviceChain(adviceChain);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Message<String> message = new GenericMessage<String>("Hello, world!");
handler.handleMessage(message);
Message<?> error = errors.receive(10000);
assertNotNull(error);
assertTrue(error.getPayload() instanceof ErrorMessageSendingRecoverer.RetryExceptionNotAvailableException);
assertNotNull(((MessagingException) error.getPayload()).getFailedMessage());
assertSame(message, ((MessagingException) error.getPayload()).getFailedMessage());
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method filterDiscardNoAdvice.
public void filterDiscardNoAdvice() {
MessageFilter filter = new MessageFilter(message -> false);
QueueChannel discardChannel = new QueueChannel();
filter.setDiscardChannel(discardChannel);
filter.handleMessage(new GenericMessage<String>("foo"));
assertNotNull(discardChannel.receive(0));
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method errorMessageSendingRecovererTests.
@Test
public void errorMessageSendingRecovererTests() {
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
throw new RuntimeException("fooException");
}
};
QueueChannel errors = new QueueChannel();
RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice();
ErrorMessageSendingRecoverer recoverer = new ErrorMessageSendingRecoverer(errors);
advice.setRecoveryCallback(recoverer);
List<Advice> adviceChain = new ArrayList<Advice>();
adviceChain.add(advice);
handler.setAdviceChain(adviceChain);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Message<String> message = new GenericMessage<String>("Hello, world!");
handler.handleMessage(message);
Message<?> error = errors.receive(10000);
assertNotNull(error);
assertEquals("fooException", ((Exception) error.getPayload()).getCause().getMessage());
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method testINT2858RetryAdviceAsNestedInAdviceChain.
@Test
public void testINT2858RetryAdviceAsNestedInAdviceChain() {
final AtomicInteger counter = new AtomicInteger(0);
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return "foo";
}
};
QueueChannel replies = new QueueChannel();
handler.setOutputChannel(replies);
List<Advice> adviceChain = new ArrayList<Advice>();
ExpressionEvaluatingRequestHandlerAdvice expressionAdvice = new ExpressionEvaluatingRequestHandlerAdvice();
expressionAdvice.setBeanFactory(mock(BeanFactory.class));
// MessagingException / RuntimeException
expressionAdvice.setOnFailureExpressionString("#exception.cause.message");
expressionAdvice.setReturnFailureExpressionResult(true);
final AtomicInteger outerCounter = new AtomicInteger();
adviceChain.add(new AbstractRequestHandlerAdvice() {
@Override
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
outerCounter.incrementAndGet();
return callback.execute();
}
});
adviceChain.add(expressionAdvice);
adviceChain.add(new RequestHandlerRetryAdvice());
adviceChain.add((MethodInterceptor) invocation -> {
throw new RuntimeException("intentional: " + counter.incrementAndGet());
});
handler.setAdviceChain(adviceChain);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage<String>("test"));
Message<?> receive = replies.receive(10000);
assertNotNull(receive);
assertEquals("intentional: 3", receive.getPayload());
assertEquals(1, outerCounter.get());
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method testClassAsKeyResolution.
@Test
public void testClassAsKeyResolution() {
QueueChannel stringsChannel = new QueueChannel();
QueueChannel numbersChannel = new QueueChannel();
TestChannelResolver channelResolver = new TestChannelResolver();
channelResolver.addChannel("stringsChannel", stringsChannel);
channelResolver.addChannel("numbersChannel", numbersChannel);
MethodInvokingRouter router = new MethodInvokingRouter(new ClassAsKeyTestBean());
router.setChannelResolver(channelResolver);
router.setChannelMapping(String.class.getName(), "stringsChannel");
router.setChannelMapping(Integer.class.getName(), "numbersChannel");
Message<?> message = new GenericMessage<>("bar");
router.handleMessage(message);
Message<?> replyMessage = stringsChannel.receive(10000);
assertNotNull(replyMessage);
assertEquals(message, replyMessage);
message = new GenericMessage<>(11);
router.handleMessage(message);
replyMessage = numbersChannel.receive(10000);
assertNotNull(replyMessage);
assertEquals(message, replyMessage);
}
Aggregations