Insomnium February 2016

Spring integration dsl: http outbound gateway

Faced spring integration java-dsl issue, I'm stuck. This is a code I have for my flow declaration:

    @Bean
    public IntegrationFlow orchestrationFlow() {
        return IntegrationFlows.from(
                Jms.messageDrivenChannelAdapter(queueConnectionFactory())
                        .destination(bookingQueue())
                        .outputChannel(bookingChannel()))
                .<String, BookingRequest>transform(s -> {
                    Ticket t = new Gson().fromJson(s, Ticket.class);
                    return new BookingRequest()
                            .setMovieId(t.getMovie().getId())
                            .setRow(t.getSeat().getRow())
                            .setSeat(t.getSeat().getNumber())
                            .setScreenNumber(t.getScreenNumber()
                            );
                })
                // HTTP part goes here
                .<BookingRequest, HttpEntity>transform(HttpEntity::new)
                .handle(
                        Http.outboundChannelAdapter(bookingServerUrl)
                                .httpMethod(HttpMethod.POST)
                                .extractPayload(true)
                                .expectedResponseType(BookStatus.class)
                )
                // and here HTTP part ends
                .handle(
                        Jms.outboundAdapter(responseDestinationTemplate())
                )
                .get();
    }

And everything was OK until I utilized HTTP outbound channel adapter. I need to call simple RESTful interface and code above does it pretty well. But, following Jms.outboundAdapter(responseDestinationTemplate()) line leads to nothing, no action performes after successfull http call.

If I remove http flow part (surrounded by comments) - it works. Implemented so much stuff, almost understood and saw beauty and simplicity of integration ...aand this is it. Yet another p

Answers


Artem Bilan February 2016

Spring Integration provides two MessageHandler types: one-way - just handle message and stop. And another one is like: handle request message and produce reply to the output channel.

The first one is called like outboundChannelAdapter and with your HTTP case you just only send a POST request and don't worry about the reply.

Since the message flow is stopped on the outboundChannelAdapter no any further action is possible in the integration chain. Like in your case the next Jms.outboundAdapter won't be reached.

If you really expect the reply from your REST service you should use Http.outboundGateway instead. And your BookStatus will be sent to the JMS as you'd like by your last .handle() in the flow.

Post Status

Asked in February 2016
Viewed 1,824 times
Voted 12
Answered 1 times

Search




Leave an answer