这是正确的,因为发送到输出通道不包含在建议中。这只是为了 请求 部分。请仔细阅读有关问题的文档: https://docs.spring.io/spring-integration/docs/5.0.8.RELEASE/reference/html/messaging-endpoints-chapter.html#message-handler-advice-chain 。该建议仅适用于 handleRequestMessage() 方法。
handleRequestMessage()
的 UPDATE 强>
对于用例,当您想要处理有限大小的队列并通过重试进行一些错误处理时,我建议您将分割结果输出到 service-activator 在...周围 @MessagingGateway 适当的 error-channel 并且可能 @Retryable 在...上 @Gateway 方法:
service-activator
@MessagingGateway
error-channel
@Retryable
@Gateway
<splitter input-channel="sourceTicketsSplitter" output-channel="gatewayInputChannel"> <poller fixed-rate="10" /> </splitter> <service-activator input-channel="gatewayInputChannel" ref="gateway"> <request-handler-advice-chain> <ref bean="retrier" /> </request-handler-advice-chain> </service-activator> <gateway id="gateway" default-request-channel="sourceTicketChannel"/>
如果你的流量是 单程 而且你不希望得到任何回复 regulatoryChainFlow ,然后是默认值 RequestReplyExchanger 不符合您的要求,您需要为网关引入一个简单的界面 void 方法和配置 <gateway> 为此 service-interface 。
regulatoryChainFlow
RequestReplyExchanger
void
<gateway>
service-interface
我忘了提到你需要使用一个 timeout 用于发送到有限的队列。如果没有这样的时间,发件人就会坐下来等待房间,这些房间会在提到之后出现 Thread.sleep(10000); 。
timeout
Thread.sleep(10000);
所以,你需要的是这样的:
<int:gateway id="stateGateWay" default-request-channel="stateChannel" default-request-timeout="100" service-interface="com.biswo.myspringapp.gateway.StateGateWay" />
注意:
<xsd:attribute name="default-request-timeout" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Provides the amount of time dispatcher would wait to send a message. This timeout would only apply if there is a potential to block in the send call. For example if this gateway is hooked up to a Queue channel.? Value is specified in milliseconds; it can be a simple long value or a SpEL expression; array variable #args is available. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute>
在此之后我开始在日志中看到reties然后 Dispatcher has no subscribers :
Dispatcher has no subscribers
2018-10-09 14:53:03.466 TRACE 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : RetryContext retrieved: [RetryContext: count=0, lastException=null, exhausted=false] 2018-10-09 14:53:03.466 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Retry: count=0 2018-10-09 14:53:03.568 DEBUG 15808 --- [ask-scheduler-3] o.s.r.backoff.ExponentialBackOffPolicy : Sleeping for 100 2018-10-09 14:53:03.669 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Checking for rethrow: count=1 2018-10-09 14:53:03.669 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Retry: count=1 2018-10-09 14:53:03.771 DEBUG 15808 --- [ask-scheduler-3] o.s.r.backoff.ExponentialBackOffPolicy : Sleeping for 500 2018-10-09 14:53:04.271 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Checking for rethrow: count=2 2018-10-09 14:53:04.271 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Retry: count=2 2018-10-09 14:53:04.372 DEBUG 15808 --- [ask-scheduler-3] o.s.r.backoff.ExponentialBackOffPolicy : Sleeping for 600 2018-10-09 14:53:04.973 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Checking for rethrow: count=3 2018-10-09 14:53:04.973 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Retry: count=3 2018-10-09 14:53:05.073 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Checking for rethrow: count=4 2018-10-09 14:53:05.073 DEBUG 15808 --- [ask-scheduler-3] o.s.retry.support.RetryTemplate : Retry failed last attempt: count=4 2018-10-09 14:53:05.077 WARN 15808 --- [ask-scheduler-3] o.s.i.c.MessagePublishingErrorHandler : Error message was not delivered. org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application.errorChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=ErrorMessage [payload=org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application.errorChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=ErrorMessage [payload=org.springframework.messaging.MessageHandlingException: nested exception is org.springframework.messaging.MessageDeliveryException: Failed to send message to channel 'stateChannel' within timeout: 100, failedMessage=GenericMessage [payload=State [id=2426, name=Pamanzi, countryId=141], headers={id=710d13df-dfbb-ba95-8d28-4785d1a1e3d3, timestamp=1539111184973}], failedMessage=GenericMessage [payload=State [id=2426, name=Pamanzi, countryId=141], headers={COUNTRY_ID=141, sequenceNumber=2, COUNTRY=com.biswo.myspringapp.model.Country@5fd4ea2d, sequenceSize=2, correlationId=ab423aa4-c80e-6af0-33a8-f57337f25352, id=a70d6b11-fc23-edd9-7973-1342c3fab8a6, timestamp=1539111183466}], headers={id=ee0ffd29-8e6a-ab5a-6ffb-1016fa38457e, timestamp=1539111185074}], failedMessage=ErrorMessage [payload=org.springframework.messaging.MessageHandlingException: nested exception is org.springframework.messaging.MessageDeliveryException: Failed to send message to channel 'stateChannel' within timeout: 100, failedMessage=GenericMessage [payload=State [id=2426, name=Pamanzi, countryId=141], headers={id=710d13df-dfbb-ba95-8d28-4785d1a1e3d3, timestamp=1539111184973}], failedMessage=GenericMessage [payload=State [id=2426, name=Pamanzi, countryId=141], headers={COUNTRY_ID=141, sequenceNumber=2, COUNTRY=com.biswo.myspringapp.model.Country@5fd4ea2d, sequenceSize=2, correlationId=ab423aa4-c80e-6af0-33a8-f57337f25352, id=a70d6b11-fc23-edd9-7973-1342c3fab8a6, timestamp=1539111183466}], headers={id=ee0ffd29-8e6a-ab5a-6ffb-1016fa38457e, timestamp=1539111185074}], headers={id=34d0e6e6-0af8-1078-5dd7-aa6643ba6c8d, timestamp=1539111185075}] for original GenericMessage [payload=[State [id=2425, name=Mayotte, countryId=141], State [id=2426, name=Pamanzi, countryId=141]], headers={COUNTRY_ID=141, id=ab423aa4-c80e-6af0-33a8-f57337f25352, COUNTRY=com.biswo.myspringapp.model.Country@5fd4ea2d, timestamp=1539111183462}]
只是因为你的 errorChannel 是一个 DirectChannel 而且没有任何消费者。
errorChannel
DirectChannel