Ada*_*lik 5 integration messaging design-patterns spring-integration
我正在使用Spring Integration(4.2.2)和Spring Integration Java DSL(1.1.0).我有两种情况需要与HTTP集成其他服务.我不确定是使用出站通道适配器还是出站网关.我想两者都会在技术上有效,但什么是"最佳实践"?
我不是在等待回复中的任何数据,但我会等待响应代码 - 2xx或错误(4xx/5xx).调用者应该阻止调用,如果是HTTP错误响应代码,调用者应该收到异常.当我使用出站通道适配器时,这工作正常,但我想知道使用出站网关是否更可取?
我已经阅读了有关出站通道适配器和出站网关之间区别的一般问题,但我不确定它是如何适用于我的情况的.
我的代码:
@Component
public class Notifier { // this is the client
@Autowired
public MessageChannel notificationChannel;
public void notifySuccess(String applicationNumber) {
// this should block until a HTTP response is received an should throw an exception if HTTP error code was returned
notificationChannel.send(new GenericMessage<>(new SuccessMessage()));
}
}
@Configuration
public class NotificationConfig {
@Bean
public MessageChannel notificationChannel() {
return MessageChannels.direct().get();
}
@Bean
public IntegrationFlow notificationFlow(@Value("${url.notification}") URI notificationUrl) {
return IntegrationFlows.from(notificationChannel())
.handle(Http.outboundChannelAdapter(notificationUrl)) // I'm wondering about this part
.get();
}
}
Run Code Online (Sandbox Code Playgroud)
答案很简单; 通道适配器用于单向集成 - 当消息发送到出站通道适配器时,流程结束(发射并忘记); 网关用于双向集成(请求 - 回复).这在端点快速参考中进行了总结.
你不等待任何数据的事实是无关紧要的; 您需要等待来自端点的回复(状态代码).因此,网关就是您所需要的.
| 归档时间: |
|
| 查看次数: |
1411 次 |
| 最近记录: |