/** * Set an additional delay to apply when retrying after a release failure. * Default {@value DelayHandler#DEFAULT_RETRY_DELAY}. * @param retryDelay the retry delay. * @return the endpoint spec. * @see #maxAttempts(int) * @since 5.0.8 */ public DelayerEndpointSpec retryDelay(long retryDelay) { this.handler.setRetryDelay(retryDelay); return this; }
@Test public void testLateReply() { ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", getClass()); DelayHandler delayHandler = ac.getBean(DelayHandler.class); delayHandler.setMaxAttempts(2); delayHandler.setRetryDelay(10); Bar baz = ac.getBean(Bar.class); String reply = baz.lateReply("hello", 1000, 0); assertNull(reply); PollableChannel errorChannel = ac.getBean("errorChannel", PollableChannel.class); Message<?> receive = errorChannel.receive(10000); assertNotNull(receive); MessagingException messagingException = (MessagingException) receive.getPayload(); assertThat(messagingException.getMessage(), startsWith("Reply message received but the receiving thread has exited due to a timeout")); ac.close(); }
/** * Set an additional delay to apply when retrying after a release failure. * Default {@value DelayHandler#DEFAULT_RETRY_DELAY}. * @param retryDelay the retry delay. * @return the endpoint spec. * @see #maxAttempts(int) * @since 5.0.8 */ public DelayerEndpointSpec retryDelay(long retryDelay) { this.handler.setRetryDelay(retryDelay); return this; }
@Test public void errorFlowAndRetries() throws Exception { delayHandler.setDefaultDelay(10); delayHandler.setRetryDelay(15); startDelayerHandler(); Message<?> message = MessageBuilder.withPayload("test")
@Test public void errorChannelHeaderAndHandlerThrowsExceptionWithDelay() { this.delayHandler.setRetryDelay(1); DirectChannel errorChannel = new DirectChannel(); MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(); errorHandler.setDefaultErrorChannel(errorChannel); taskScheduler.setErrorHandler(errorHandler); this.setDelayExpression(); startDelayerHandler(); output.unsubscribe(resultHandler); errorChannel.subscribe(resultHandler); output.subscribe(message -> { throw new UnsupportedOperationException("intentional test failure"); }); Message<?> message = MessageBuilder.withPayload("test") .setHeader("delay", "10") .setErrorChannel(errorChannel).build(); input.send(message); waitForLatch(10000); Message<?> errorMessage = resultHandler.lastMessage; assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass()); MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload(); assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload()); assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass()); assertNotSame(Thread.currentThread(), resultHandler.lastThread); }
@Test public void defaultErrorChannelAndHandlerThrowsExceptionWithDelay() { this.delayHandler.setRetryDelay(1); StaticApplicationContext context = new StaticApplicationContext(); context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class); context.refresh(); DirectChannel defaultErrorChannel = (DirectChannel) context .getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME); MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(); errorHandler.setBeanFactory(context); taskScheduler.setErrorHandler(errorHandler); this.setDelayExpression(); startDelayerHandler(); output.unsubscribe(resultHandler); defaultErrorChannel.subscribe(resultHandler); output.subscribe(message -> { throw new UnsupportedOperationException("intentional test failure"); }); Message<?> message = MessageBuilder.withPayload("test") .setHeader("delay", "10").build(); input.send(message); waitForLatch(10000); Message<?> errorMessage = resultHandler.lastMessage; assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass()); MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload(); assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload()); assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass()); assertNotSame(Thread.currentThread(), resultHandler.lastThread); }
@Test public void errorChannelNameHeaderAndHandlerThrowsExceptionWithDelay() { this.delayHandler.setRetryDelay(1); String errorChannelName = "customErrorChannel"; StaticApplicationContext context = new StaticApplicationContext();