![]() |
Spring Cloud Stream Event Routing is the ability to route events to a specific event subscriber or a specific destination. Routes ‘TO’ and ‘FROM’ will be used here. Using the Spring Cloud Stream architecture, developers may create extremely scalable event-driven microservices that are integrated with common messaging platforms. With support for persistent pub/sub semantics, consumer groups, and stateful partitions, among other features, the framework offers a versatile programming paradigm that is based on well-known and established Spring idioms and best practices. Dependencies to Spring Cloud StreamFirst, we must add the appropriate binder implementation library in our application before we can activate Spring Cloud Stream. The spring-cloud-stream-binder-rabbit artifact is required as we are connecting with RabbitMQ. There are no further dependencies that need to be included because it references all other necessary libraries. <dependency> Routing TO ConsumerRouting may be accomplished by using the RoutingFunction, which is provided in Spring Cloud Function 3.0. All you have to do is activate it using the application parameter –spring.cloud.stream.function.routing.enabled=true or give the spring.cloud.function.routing-expression. Message headersMessage header means passing some message or value to the header. By setting the spring.cloud.function.routing-expression header to value “even” and “odd” will end up routing request to either odd or even functions. Java
Application propertiesIt is possible to send the spring.cloud.function.definition or spring.cloud.function.routing-expression as application properties spring.cloud.function.routing-expression=headers[‘type’] is one example. Java
Routing FROM ConsumerSpring Cloud Stream allows apps to deliver messages to dynamically bound destinations in addition to static ones. This is helpful, for instance, if runtime target destination determination is required. Applications have two options for doing this. spring.cloud.stream.sendto.destination:By providing the name of the destination to be resolved in the spring.cloud.stream.sendto.destination header set, you can also assign the task of dynamically resolving the output destination to the framework. Java
Routing SourcesFinally, let us see a further common application of a route “FROM”, in which the data source is external to SCSt yet has to be sent to the correct location: Java
ConclusionSo, this is Spring Cloud Stream – Event Routing. With support for persistent pub/sub semantics, consumer groups, and stateful partitions, among other features, the framework offers a versatile programming paradigm that is based on well-known and established Spring idioms and best practices. |
Reffered: https://www.geeksforgeeks.org
Advance Java |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |