简体   繁体   中英

In-Memory Binder for Spring Cloud Stream

是否有用于 Spring Cloud Stream 的轻量级“内存”绑定器,例如,它允许我将一组微服务连接在一起并在同一地址空间(即单个 Java 进程)中部署一组微服务?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM