|
49 | 49 | import org.springframework.integration.annotation.MessageEndpoint;
|
50 | 50 | import org.springframework.integration.annotation.MessagingGateway;
|
51 | 51 | import org.springframework.integration.annotation.ServiceActivator;
|
| 52 | +import org.springframework.integration.channel.DirectChannel; |
52 | 53 | import org.springframework.integration.channel.FixedSubscriberChannel;
|
53 | 54 | import org.springframework.integration.channel.QueueChannel;
|
54 | 55 | import org.springframework.integration.config.EnableIntegration;
|
|
58 | 59 | import org.springframework.integration.dsl.Pollers;
|
59 | 60 | import org.springframework.integration.dsl.channel.MessageChannels;
|
60 | 61 | import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
| 62 | +import org.springframework.integration.handler.GenericHandler; |
| 63 | +import org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer; |
61 | 64 | import org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice;
|
| 65 | +import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice; |
62 | 66 | import org.springframework.integration.scheduling.PollerMetadata;
|
63 | 67 | import org.springframework.integration.store.MessageStore;
|
64 | 68 | import org.springframework.integration.store.SimpleMessageStore;
|
|
71 | 75 | import org.springframework.messaging.MessageDeliveryException;
|
72 | 76 | import org.springframework.messaging.MessageHandler;
|
73 | 77 | import org.springframework.messaging.MessageHeaders;
|
| 78 | +import org.springframework.messaging.MessagingException; |
74 | 79 | import org.springframework.messaging.PollableChannel;
|
75 | 80 | import org.springframework.messaging.SubscribableChannel;
|
76 | 81 | import org.springframework.messaging.support.ErrorMessage;
|
|
80 | 85 | import org.springframework.stereotype.Component;
|
81 | 86 | import org.springframework.stereotype.Service;
|
82 | 87 | import org.springframework.test.annotation.DirtiesContext;
|
83 |
| -import org.springframework.test.context.ContextConfiguration; |
84 | 88 | import org.springframework.test.context.junit4.SpringRunner;
|
85 | 89 |
|
86 | 90 | /**
|
@@ -415,6 +419,13 @@ public void testSubscribersSubFlows() {
|
415 | 419 | assertEquals(6, receive3.getPayload());
|
416 | 420 | }
|
417 | 421 |
|
| 422 | + @Autowired |
| 423 | + private ErrorRecovererFlowGateway errorRecovererFlowGateway; |
| 424 | + |
| 425 | + @Test |
| 426 | + public void testReplyChannelFromReplyMessage() { |
| 427 | + assertEquals("foo", this.errorRecovererFlowGateway.testIt("foo")); |
| 428 | + } |
418 | 429 |
|
419 | 430 | @MessagingGateway
|
420 | 431 | public interface ControlBusGateway {
|
@@ -681,6 +692,42 @@ public MessageChannel gatewayError() {
|
681 | 692 | return MessageChannels.queue().get();
|
682 | 693 | }
|
683 | 694 |
|
| 695 | + @Bean |
| 696 | + public IntegrationFlow errorRecovererFlow() { |
| 697 | + return IntegrationFlows.from(ErrorRecovererFlowGateway.class) |
| 698 | + .handle((GenericHandler<?>) (p, h) -> { |
| 699 | + throw new RuntimeException("intentional"); |
| 700 | + }, e -> e.advice(retryAdvice())) |
| 701 | + .get(); |
| 702 | + } |
| 703 | + |
| 704 | + @Bean |
| 705 | + public RequestHandlerRetryAdvice retryAdvice() { |
| 706 | + RequestHandlerRetryAdvice requestHandlerRetryAdvice = new RequestHandlerRetryAdvice(); |
| 707 | + requestHandlerRetryAdvice.setRecoveryCallback(new ErrorMessageSendingRecoverer(recoveryChannel())); |
| 708 | + return requestHandlerRetryAdvice; |
| 709 | + } |
| 710 | + |
| 711 | + @Bean |
| 712 | + public MessageChannel recoveryChannel() { |
| 713 | + return new DirectChannel(); |
| 714 | + } |
| 715 | + |
| 716 | + @Bean |
| 717 | + public IntegrationFlow recoveryFlow() { |
| 718 | + return IntegrationFlows.from(recoveryChannel()) |
| 719 | + .<MessagingException, Message>transform(MessagingException::getFailedMessage) |
| 720 | + .get(); |
| 721 | + |
| 722 | + } |
| 723 | + |
| 724 | + } |
| 725 | + |
| 726 | + @MessagingGateway |
| 727 | + private interface ErrorRecovererFlowGateway { |
| 728 | + |
| 729 | + String testIt(String payload); |
| 730 | + |
684 | 731 | }
|
685 | 732 |
|
686 | 733 | @Service
|
|
0 commit comments