<int:transformer id="errorHandler"
input-channel="errorChannel"
ref="myTransformer" method="transform" />
<bean id="myTransformer" class="com.sample.MyTransformer" />
public class MyTransformer {
private static Logger logger = Logger.getLogger(MyTransformer.class);
public String transform(org.springframework.integration.handler.ReplyRequiredException e) {
logger.error("timeout exception is thrown");
return "Error in processing request.";
}
}
上面的代码可以工作,客户端得到“处理请求中的错误”,服务器日志中有一个条目“Timeout exception is through”。但我在日志中也看到以下异常:
2016-06-30 16:25:27,827 ERROR [org.springframework.integration.handler.LoggingHandler] org.springframework.integration.handler.ReplyRequiredException: No reply produced by handler 'org.springframework.integration.config.ServiceActivatorFactoryBean#0', and its 'requiresReply' property is set to true.
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:150)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:42)
at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:97)
at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:422)
at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:390)
at org.springframework.integration.ip.tcp.TcpInboundGateway.doOnMessage(TcpInboundGateway.java:119)
at org.springframework.integration.ip.tcp.TcpInboundGateway.onMessage(TcpInboundGateway.java:97)
at org.springframework.integration.ip.tcp.connection.TcpNetConnection.run(TcpNetConnection.java:182)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
MyTransformer的实现似乎不正确。
你能帮我定制变压器吗?如何在转换方法中获得有效负载,这样我就可以回复客户机作为‘处理请求的错误。有效载荷='+有效载荷?
<int-ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="crLfServer"
request-channel="requestChannel"
error-channel="tcpErrorChannel"
reply-timeout="10000"
/>
<int:channel id="tcpErrorChannel" />
<int:service-activator input-channel="requestChannel" ref="gateway" requires-reply="true"/>
<int:gateway id="gateway" default-request-channel="timeoutChannel" default-reply-timeout="10000" />
<int:object-to-string-transformer id="serverBytes2String"
input-channel="timeoutChannel"
output-channel="serviceChannel"/>
<int:channel id="timeoutChannel">
<int:dispatcher task-executor="timeoutExecutor"/>
</int:channel>
<bean id="timeoutExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="100" />
<property name="queueCapacity" value="50" />
</bean>
2016-07-05 12:17:34,266 ERROR [org.springframework.integration.ip.tcp.connection.TcpNetConnection] Exception sending message: GenericMessage [payload=byte[67], headers={timestamp=1467735444239, id=30eb099e-955d-1bd3-1789-49aa9fc84b6f, ip_tcp_remotePort=64055, ip_address=127.0.0.1, ip_localInetAddress=/127.0.0.1, ip_hostname=127.0.0.1, ip_connectionId=127.0.0.1:64055:5678:908d39a1-d027-4753-b144-59b9c0390fd7}]
org.springframework.messaging.MessagingException: failure occurred in error-handling flow; nested exception is org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.context.support.FileSystemXmlApplicationContext@4876db09.tcpErrorChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:452)
at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:390)
at org.springframework.integration.ip.tcp.TcpInboundGateway.doOnMessage(TcpInboundGateway.java:119)
at org.springframework.integration.ip.tcp.TcpInboundGateway.onMessage(TcpInboundGateway.java:97)
at org.springframework.integration.ip.tcp.connection.TcpNetConnection.run(TcpNetConnection.java:182)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.context.support.FileSystemXmlApplicationContext@4876db09.tcpErrorChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:81)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:150)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:42)
at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:97)
at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:449)
... 7 more
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:153)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
... 14 more
非常感谢Artem的完美解决方案。
看起来这是您的另一个问题的继续,在spring Integration中的tcp-inbound-gateway中的回复-超时含义。
那么,ReplyRequiredException
是
的结果。
requires-reply=“true”
-请阅读它的描述。不过,您可以使用它,并将其设置为false
(默认设置),但是您的“超时”逻辑将不起作用。所以,你别无选择,除非继续忍受:
ERROR [org.springframework.integration.handler.LoggingHandler] org.springframework.integration.handler.ReplyRequiredException
不过,这只是默认errorchannel
订阅方之一的影响:http://docs.spring.io/spring-integration/reference/html/configuration.html#namespace-errorhandler。
关于你的最后一个问题。所有异常都包装到ErrorMessage
中,并发送到ErrorChannel
中。通常,异常被包装到MessagingException
中,例如,在本例中如下所示:
else if (this.requiresReply && !isAsync()) {
throw new ReplyRequiredException(message, "No reply produced by handler '" +
getComponentName() + "', and its 'requiresReply' property is set to true.");
}
请注意message
ctor参数,它正是一个requestmessage
,在我们的场景中没有应答。您可以从中提取所需的有效负载
。
更新
由于此ReplyRequiredException
是已知异常,因此不需要将其视为错误。
嗯,即使它是一个已知的异常,但它在其他组件和场景中是一个重要的异常,当它可能不合适时,不会收到回复。ReplyRequiredException
在框架组件中非常常见,因此将其转移到不同的类别对应用程序来说可能是一个很大的体系结构错误。
在下面的问题上,我可以得到一些帮助吗:调用transformer将输入对象转换为Map对象并调用处理程序,处理程序缺少之前添加的头值。为什么要将有效负载转换为映射对象,以丢失所有标头? 如果转换不是map,则标头中没有问题。 谢了湿婆
目前,我们的应用程序没有利用spring集成提供的xml转换器。相反,它创建一个JaxbContext,然后从该JaxbContext创建一个JAXB解组器/封送器池,并将其连接到服务活动器中。我们创建池是为了不产生为每个操作创建封送器和解封送器的成本。 作为重构工作的一部分,我们决定使用xml变压器。在尝试实现时,我们发现org.spring.oxm.封送器实现不支持封送器/反封送器的池,因为S
注意:本书中的 Service Mesh 章节已不再维护,请转到 istio-handbook 中浏览。 例如Istio这样的Service Mesh中有很多地方可以给大家定制,例如作为数据平面的sidecar,虽然默认使用的是Envoy,但是你可以开发自己的sidecar代理;还有Mixer中的各种adpater,你也可以开发自己的adapter来扩展遥测和鉴权功能,Consul Connect
null 如何在transform()步骤中添加Jaxb2Marshaller?
我需要在Sftp服务器中复制/复制远程文件,复制时也要重命名,我在这里读到在Sftp中复制远程文件是不受支持的,所以唯一可用的选项是将文件放入本地,然后再放入Sftp&删除本地文件,我已经成功地实现了我的目标,但问题是有一个日志打印从我不知道它从哪里来。 这是原木。 更令人惊讶的是,它出现的很早,甚至在流执行之前,尽管我已经处理了文件删除最后。我怎样才能摆脱这条日志消息?虽然它不会影响我的进程,但
我是spring集成和缓存新手,想知道如何将从出站网关接收到的对象添加到缓存中。无法确定所需的配置。 从以下配置,我从rest api收到的对象正在被记录: INFO:com.domain.IpAddress@74589991 我计划使用ehcache/caffiene,任何提示都会有帮助。 编辑2: 现在,我按照建议更改了出站网关: 并将ehache配置定义如下: 在我的服务类中,定义了可缓存的