spring - 如何在spring集成中为HttpRequestExecutingMessageHandler声明outputChannel并处理http响应
问题描述
下面是 HttpRequestExecutingMessageHandler 的配置
@Bean
@ServiceActivator(inputChannel = "httpRequestChannel")
public HttpRequestExecutingMessageHandler httpRequestExecutingMessageHandler() {
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(serviceUrl);
handler.setCharset(StandardCharsets.UTF_8.displayName());
handler.setOutputChannel(httpResponseChannel());
handler.setExpectedResponseType(String.class);
return handler;
}
我应该如何配置 httpResponseChannel 来处理 httpResponse。如果http状态代码为201,我想将原始文件移动到成功文件夹或错误文件夹以供休息。
我将 spring integration 5 与 spring boot 一起使用。
解决方案
这不是httpResponseChannel
责任。您需要考虑为此添加一个ExpressionEvaluatingRequestHandlerAdvice
:HttpRequestExecutingMessageHandler
https: //docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/messaging-endpoints-chapter.html#expression-advice
并且已经在那里,您可以做出成功或失败的决定。
有这个@ServiceActivator
选项:
/**
* Specify a "chain" of {@code Advice} beans that will "wrap" the message handler.
* Only the handler is advised, not the downstream flow.
* @return the advice chain.
*/
String[] adviceChain() default { };
推荐阅读
- typescript - 有什么好的方法可以调试 vuejs 计算的属性和模板吗?
- azure-devops - 是否有任何选项可以在 azure devops 服务中合并两个不同的组织?
- machine-learning - 训练分类算法所花费的时间
- angular - crossfilter2__WEBPACK_IMPORTED_MODULE_3__ 不是函数
- node.js - NestJS(Node)项目通过NEST CLI创建新项目时出错
- objective-c - 将 Swift 转换为 Objective C
- scala - java.lang.ClassCast errors.GenericRowWithSchema 不能转换为 scala.collection.Seq
- c# - 检查并验证以某个值开头的某个数字是否可用
- c - MINIX 3.3.0:如何添加新的命令二进制文件?
- c# - asp.net core方法中如何将var定义为全局变量