Home > Software design >  In-Memory Binder for Spring Cloud Stream
In-Memory Binder for Spring Cloud Stream

Time:10-15

Is there a lightweight 'in-memory' binder for Spring Cloud Stream that would allow me, for example, to wire together and deploy a set of microservices in the same address space (i.e. a single Java process)?

CodePudding user response:

There is not an in-memory binder but, when using the (preferred) functional programming model (not the deprecated annotation-based model), you can compose multiple functions together.

https://docs.spring.io/spring-cloud-stream/docs/3.1.4/reference/html/spring-cloud-stream.html#_functional_composition

Functional Composition Using functional programming model you can also benefit from functional composition where you can dynamically compose complex handlers from a set of simple functions. As an example let’s add the following function bean to the application defined above

@Bean
public Function<String, String> wrapInQuotes() {
    return s -> "\""   s   "\"";
}

and modify the spring.cloud.function.definition property to reflect your intention to compose a new function from both ‘toUpperCase’ and ‘wrapInQuotes’. To do so Spring Cloud Function relies on | (pipe) symbol. So, to finish our example our property will now look like this:

--spring.cloud.function.definition=toUpperCase|wrapInQuotes

CodePudding user response:

Let me clarify a little There is an in-memory binder that was specifically build for testing - https://docs.spring.io/spring-cloud-stream/docs/3.1.4/reference/html/spring-cloud-stream.html#_testing. We use it all the time. However, i want to stress that it was not build for any production usage. For that we simply have Spring Integration project that allows you to wire complex flow. Spring Cloud Stream is actually build on top of Spring Integration, but build specifically for distributed microservices. So any attempt to subvert that would be an anti-pattern.

  • Related