Imagine you have an application (let's call it B) with an inbound HTTP interface (using HTTP is a requirement). You will call it from several different other applications in the future but at the moment you only want to develop a single client (let's call it A). So in A, there is an outbound HTTP gateway:
A (outbound gateway) ---[HTTP]---> (inbound gateway) B
Is it possible to share code e.g. the HTTP API definition like path (for example "/hello"), method (GET, POST, PUT...), maybe parameters/their type/response between these two apps? If yes, how?
I would like to use the Java DSL but I see that Http.inboundGateway("..")
and Http.outboundGateway("..")
are totally different (e.g. the type) so I am not sure. Ideally I could have something like:
@Bean
public IntegrationFlow inbound() {
return IntegrationFlows.from(apiDefinition)...
.get();
...
...
@Bean
public IntegrationFlow outbound() {
return IntegrationFlows.from(somehwere)...
.handle(with(apiDefinition))
.get();
Api Definition can be imagined like the following (pseudocode):
apiDefinition =
method: GET
path: /items/{id}
parameters:
id: string
response: item
Well, it sounds more like you don't want to do a call over HTTP in that your client and be able to get directly to the business logic. In this case the best thing what exist in Spring Integration is a
MessageChannel
abstraction. So, no matter what is an input endpoint (HTTP, JMS, Apache Kafka, JDBC etc.), you always can point them to the same channel where some service activator is a subscriber to that channel to perform desired business logic.So, to by pass an HTTP call in your current client, you just need to introduce a
MessageChannel
as an input for someIntegationFlow
with business logic. The HTTP inbound flow would use a.channel(myBusinessLogicChannel)
. And your outbound would do the same in its logic. This way you would have two clients for the same API: one over HTTP and another one direct.I also can recommend to investigate what is a Messaging Gateway as an alternative to design a high level API with minor messaging interaction from the client perspective. The outcome would be the same: HTTP inbound flow could call that gateway. And it can be used in the other end-user code to be called directly.
See more docs about channels and gateways:
https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway