jeudi 3 décembre 2015

Outbound channel adapter vs. outbound gateway for HTTP communication

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 - OK or an error. 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?

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();
    }
}

Aucun commentaire:

Enregistrer un commentaire