Skip to content

Instantly share code, notes, and snippets.

@knalli
Last active March 25, 2016 23:01
Show Gist options
  • Save knalli/e81a4bff19d1fb5f20d5 to your computer and use it in GitHub Desktop.
Save knalli/e81a4bff19d1fb5f20d5 to your computer and use it in GitHub Desktop.
@MessagingGateway
public interface ApiGateway {
@Gateway(requestChannel = "requestChannel", replyChannel = "resultChannel")
Response handle(Request request);
}
@MessagingGateway
public interface ApiGateway {
@Gateway(requestChannel = "requestChannel", replyChannel = "resultChannel")
CompletableFuture<Response> handle(Request request);
}
@Configuration
public class ConfigClient {
@Bean public IntegrationFlow flow() {
return IntegrationFlows.from(MessageChannels.publishSubscribe("requestChannel"))
.transform(Transformers.toJson(mapper()))
.handle(Amqp.outboundGateway(amqpTemplate).routingKey("queue"))
.transform(Transformers.fromJson(Response.class, mapper()))
.channel(MessageChannels.direct("responseChannel"))
.get();
}
}
@Configuration
public class ConfigServer {
@Autowired ConnectionFactory connectionFactory;
@Autowired ApiImpl api;
@Bean public JsonObjectMapper<?, ?> mapper() {
return new Jackson2JsonObjectMapper();
}
@Bean public IntegrationFlow flow() {
return IntegrationFlows.from(
Amqp.inboundGateway(connectionFactory, "queue")
.errorChannel("errorChannel"))
.transform(Transformers.fromJson(Request.class, mapper()))
.handle(Request.class, (request, headers) -> api.handle(request))
.transform(Transformers.toJson(mapper()))
.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment