【发布时间】:2016-03-08 00:25:39
【问题描述】:
我正在使用 Spring Integration (4.2.2) 和 Spring Integration Java DSL (1.1.0)。我有两种情况需要使用 HTTP 与其他服务集成。我不确定是使用出站通道适配器还是出站网关。我想两者在技术上都可以工作,但“最佳实践”是什么?
我不等待任何回复数据,但我确实等待响应代码 - 2xx 或错误 (4xx/5xx)。调用者应该阻止调用,如果出现 HTTP 错误响应代码,调用者应该收到异常。当我使用出站通道适配器时效果很好,但我想知道使用出站网关是否更可取?
我已经阅读了general question about the difference between outbound channel adapter and outbound gateway,但我不确定它如何适用于我的案例。
我的代码:
@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();
}
}
【问题讨论】:
标签: design-patterns integration spring-integration messaging