1

I'm consuming messages from a rabbit queue with a bean configured like so:

IntegrationFlows.from(Amqp.inboundGateway(listenerContainer()).errorChannel(FailedFlow.CHANNEL_NAME))
            .transform(Transformers.fromJson())
            .channel(TestFlow.CHANNEL_NAME)
            .get();

The message goes through some routers and header enrichers to end up in an outbound flow with a bean configured like so:

IntegrationFlows.from(CHANNEL_NAME)
            .transform(Transformers.toJson())
            .handle(Http.outboundChannelAdapter("http://localhost:8080/api/test")
                            .httpMethod(HttpMethod.POST)
                            .requestFactory(getRequestFactory()))
            .get();

This works fine while testing, but for actual use i need to send the request to different servers using a base url stored in a header that has been added earlier.

IntegrationFlows.from(CHANNEL_NAME)
            .transform(Transformers.toJson())
            .handle(e -> Http.outboundChannelAdapter(String.format("%s/test",
                    e.getHeaders().get(IntegrationConstants.NOTIFY_BASE_URL_HEADER_NAME)))
            .httpMethod(HttpMethod.POST)
            .requestFactory(getRequestFactory()))
            .get();

It seems that in the test config i'm passing a MessageHandlerSpec to the handle method and in the actual config i'm passing a MessageHandler to the handle method. I'm not sure what does the difference, all i know is that the endpoint is not called when passing the MessageHandler.

How do i access the headers while maintaining the direct use of the MessageHandlerSpec?

1 Answer 1

1
.handle(IntegrationFlows.from(CHANNEL_NAME)
                    .transform(Transformers.toJson())
                    .handle(Http.outboundChannelAdapter("{baseUrl}/test")
                            .httpMethod(HttpMethod.POST)
                            .requestFactory(getRequestFactory())
                            .uriVariable("baseUrl", e -> e.getHeaders().get(IntegrationConstants.NOTIFY_BASE_URL_HEADER_NAME)))
                    .get())

:-D

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.