Mastering Spring Cloud
上QQ阅读APP看书,第一时间看更新

Messaging and integration

I have already mentioned messaging brokers and their usage for communication between your application and Zipkin server. Generally, Spring Cloud supports two types of communications via synchronous/asynchronous HTTP and with messaging brokers. The first project from this area is Spring Cloud Bus. It allows you to send broadcast events to applications informing them about state changes such as configuration property updates or other management commands. Actually, we might want to use starters for AMQP with a RabbitMQ broker or for Apache Kafka. As usual, we only need to include spring-cloud-starter-bus-amqp or spring-cloud-starter-bus-kafka to the dependency management and all other necessary operations are performed through auto-configuration. 

Spring Cloud Bus is a rather small project allowing you to use distributed messaging features for common operations such as broadcasting configuration change events. The right framework for building a system consisting of message-driven microservices is the Spring Cloud Stream. This is a really powerful framework and one of the biggest Spring Cloud projects, to which I have dedicated an entire chapter, Chapter 11, Message Driven Microservices, of the book. The same as for Spring Cloud Bus, there are two binders available, first for AMQP with RabbitMQ, and second for Apache Kafka. Spring Cloud Stream is based on Spring Integration, which is another large project part of Spring. It provides a programming model, supporting most Enterprise Integration Patterns such as endpoint, channel, aggregator, or transformer. The applications included in the whole microservice system communicate with each other through the Spring Cloud Stream input and output channels. The main communication model between them is Publish/Subscribe, where messages are broadcast through shared topics. Additionally, it is important to support multi instances of every microservice. In most cases, a message should be processed only by a single instance, which is not supported in a Publish/Subscribe model. That's why Spring Cloud Stream introduces grouping mechanisms where only one member of the group receives a message from a destination. The same as earlier, these are two starters that can include a project depending on the binder type spring-cloud-starter-stream-kafka or spring-cloud-starter-stream-rabbit

There are two more projects related to Spring Cloud Stream. First, Spring Cloud Stream App Starters defines a set of Spring Cloud Stream applications that can be run independently or using the second project, Spring Cloud Data Flow. Among these applications, we can distinguish connectors, adapters for network protocols, and generic protocols. Spring Cloud Data Flow is another extensive and powerful Spring Cloud toolkit. It simplifies development and deployment by providing a smart solution for building data integration and real-time data processing pipelines. The orchestration of microservice-based data pipelines is achieved with simple DSL, a drag-and-drop UI dashboard, and REST APIs together.