Dhiren Dash
Dhiren Dash

Reputation: 111

Reply Channel for Messaging Gateway using Java DSL

I have a REST API which receives a POST request from a client application.

@Autowired
private EdiTranslationEvents.TransformToString transformToString;

@PostMapping("/testPost")
@ResponseStatus(HttpStatus.OK)
public String testPostLogging(@RequestBody Student student) {
    log.info("In controller....");
    System.out.println(this.transformToString.objectToInputGateway(student));
    return "testPost logging";
}

As you can see, in the controller, I have an autowired messaging gateway and I am using it to send data to a channel.

@Configuration
@EnableIntegration
public class EdiTranslationEvents {

    @Component
    @MessagingGateway
    public interface TransformToString {

        @Gateway(requestChannel = "inputObjectChannel")
        String objectToInputGateway(Student student);
    }

    @Bean
    public IntegrationFlow inputObjectString() {
        return IntegrationFlows.from(inputObjectChannel())
                .transform(Transformers.objectToString())
                .log(LoggingHandler.Level.DEBUG, "com.dash.Logger")
                .get();
    }
}

When I send data to the REST API, the API just hangs. The gateway does not return anything. I have the return type specified, and I was assuming that the gateway creates a temporary reply channel and sends the response to that channel.

However, I am not doing anything in the DSL configuration for creating or managing a reply. So, how do I send a reply back to the reply channel from the DSL flow?

Upvotes: 1

Views: 942

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

Your current flow does not return a value, you are simply logging the message.

A terminating .log() ends the flow.

Delete the .log() element so the result of the transform will automatically be routed back to the gateway.

Or add a .bridge() (a bridge to nowhere) after the log and it will bridge the output to the reply channel.

Upvotes: 3

Related Questions