I'm using Spring Integration (4.2.2) and Spring Integration Java DSL (1.1.0). I have two cases where I need to integrate with other services with HTTP. I'm not sure whether to use an outbound channel adapter or an outbound gateway. I guess both would work technically, but what is the "best practice"?
I'm not waiting for any data in reply, I do wait however for a response code - 2xx or an error (4xx/5xx). The caller should block on the call and in case of a HTTP error response code the caller should receive an exception. That works fine when I'm using outbound channel adapter, but I'm wondering if using an outbound gateway would be more advisable?
I've read the general question about the difference between outbound channel adapter and outbound gateway, but I'm not sure how it applies to my case.
My code:
@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();
}
}