I have been reading through the documentation for Spring Integration, but I still can't figure out how to model the following integration:
+----------+ --- (request) --> +----------+ --- (request) --> +----------+
| Service1 | | RabbitMQ | | Service2 |
+----------+ <--- (reply) ---- +----------+ <--- (reply) ---- +----------+
Basically what I would like to be able to do is to share an interface between Service 1
and Service 2
, say
public interface Service2 {
int sum(int a, int b);
int subtract(int a, int b);
}
and be able to call
service2proxyInstance.sum(1, 2)
on some kind auto-generated proxy class inside Service1
.
From what I read I think I must use an OutboundGateway
in Service1
and an InboundGateway
in Service2
, but I can't seem to put them together. Could anyone please shed some light and maybe provide a very simple example? All the examples in Spring Integration seem to use XML configuration, but as I am pretty new to Spring and used to annotation-based config I can't read them adequately.
Not sure how to help you since you have already said everything correctly.
Your service one should be as a @MessagingGateway
or call such one. That should send a message to a channel for the AmqpOutboundEndpoint
and wait for reply from there. That is really done automatically by @MessagingGateway
.
You payload
will be serialized if it is POJO not String or something for JSON-marshalling.
Another application should start from the AmqpInboundGateway
, send a request to the Service2 for the deserialized payload
and wait for the reply from there to send back to your Service1 in the end.
Take a look into Spring Integration Java DSL and AMQP tests there.
And share you PoC and your concerns therefor better understanding what's going on.