Spring Cloud Stream – Composed Functions or EIP
Spring Cloud Stream is a framework for creating highly scalable event-driven microservices that communicate over common messaging systems. The framework provides a versatile programming architecture based on well-known Spring idioms and best practices, such as support for persistent pub/sub semantics, consumer groups, and stateful partitioning.
Java
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application. class , args); } @Bean public Function<String, String> uppercase() { return value -> value.toUpperCase(); } } |
Spring Cloud Stream Core Building Blocks
- Message: The standard data format that producers and consumers use to exchange information with Destination Binders.
- Destination Binders: Parts in charge of offering integration with outside message platforms.
- Destination Bindings: A link between the application code that the end user provides and the external messaging services.
Composed Functions or EIP
Function Composition
A declarative method of composing many functions together is possible using SCF’s function composition feature. This is demonstrated by the example as below:
--spring.cloud.function.definition=uppercase|reverse
Enterprise Integration Patterns (EIP)
A collection of precisely defined and comprehended patterns, known as enterprise integration, patterns, enables you to characterize a business case. Filter, transformer, router, and so forth are a few examples. Click this link to learn more about EIP. Spring provides a reference implementation of EIP using the Spring Integration framework.
IntegrationFlow.fromChannel(inputChannel)
.transform(uppercase)
.transform(reverse);
Using Two Applications Spring Cloud Stream – Composed Functions
The functionality of the two apps in the Stream (http | transformer) is combined into a single application, which we construct and register. The new stream is then put into use, and we confirm that the output matches that of the prior example.
Java
@SpringBootApplication @Import (org.springframework.cloud.stream.app.http.source.HttpSourceConfiguration. class ) public class HttpSourceRabbitApplication { @Bean public Function<String, String> upper() { return value -> value.toUpperCase(); } @Bean public Function<String, String> concat() { return value -> "Hello " + value; } public static void main(String[] args) { SpringApplication.run(HttpSourceRabbitApplication. class , args); } } |
Conclusion
So, this is Spring Cloud Stream – Composed Functions or EIP. For orchestrating capabilities that are aligned in sequence, SCF Composition is a better fit, whereas SI is a better option for anything else that falls within the EIP category.
Contact Us