Home > database >  How do I use Gateway replyTimeoutExpression
How do I use Gateway replyTimeoutExpression

Time:02-18

In my application.properties I have written:

example.requestTimeoutExpression = 60000
example.replyTimeoutExpression = 60000

But how do I use this when I configure the MessagingGateway?

@Component
@MessagingGateway
public interface ExampleGateway {
    @Gateway(
        requestChannel = "exampleInput",
        replyChannel = "exampleOutput",
        requestTimeoutExpression = "???",
        replyTimeoutExpression = "???"
    )
    Object send(Object request);
}

None of these work:

  • "example.requestTimeoutExpression"
  • "#{example.requestTimeoutExpression}"
  • "${example.requestTimeoutExpression}"

While the provided solutions seem to help me with my original question. The timeout has no effect. I'm clearly misunderstanding something. This seems to have effect:

@Bean
public IntegrationFlow exampleFlow(
    @Value("${example.remoteTimeout}") long remoteTimeout
) {
    return IntegrationFlows.from("exampleInput")
        .transform(...)
        .handle(Tcp.outboundGateway(Tcp.nioClient(host, port)
                ...
            )
            .remoteTimeout(remoteTimeout)
        )
        .transform(...)
        .channel("exampleOutput")
        .get();
}

CodePudding user response:

Properties are not currently supported there; please open a new feature issue on GitHub; here is a work around:

@Bean
Long reqTimeout(@Value("${example.requestTimeoutExpression}") Long to) {
    return to;
}

@Bean
Long repTimeout(@Value("${example.replyTimeoutExpression}") Long to) {
    return to;
}
@Component
@MessagingGateway
interface ExampleGateway {

    @Gateway(
        requestChannel = "nullChannel",
        replyChannel = "exampleOutput",
        requestTimeoutExpression = "@reqTimeout",
        replyTimeoutExpression = "@repTimeout"
    )
    Object send(Object request);

}
  • Related