concept message broker in category spring

This is an excerpt from Manning's book Spring Microservices in Action, 2E.
Communication protocols. How will developers communicate with your service? The first step is to define whether we want a synchronous or asynchronous protocol. For synchronous the most common communication is HTTP-based REST using XML (Extensible Markup Language), JSON (JavaScript Object Notation), or binary protocol such as Thrift to send data back and forth your microservices. For asynchronous, the most popular protocol is AMQP (Advanced Message Queuing Protocol) and it can be implemented one-to-one (queue) or one-to-many(topic) with message brokers such as RabbitMQ, Apache Kafka and SQS. In later chapters, I’m going to be explaining the communication protocols.
In listing 10.1, the
@EnableBindingannotation tells Spring Cloud Stream that we want to bind the service to a message broker. The use ofSource.classin the@EnableBindingannotation tells Spring Cloud Stream that this service will communicate with the message broker via a set of channels defined on theSourceclass. Remember, channels sit above a message queue. Spring Cloud Stream has a default set of channels that can be configured to speak to a message broker.
Then we need to tell the licensing service that it needs to use Spring Cloud Stream to bind to a message broker. Like the organization service, we’re going to annotate the licensing services bootstrap class (
/licensing-service/src/main/java/com/optimagrowth/ license/LicenseServiceApplication.java) with the@EnableBindingannotation. The difference between the licensing service and the organization service is the value we’re going to pass to the@EnableBindingannotation, as shown in the following code listing 10.7.Listing 10.7 Consuming a message using Spring Cloud Stream
package com.optimagrowth.license; //Imports and rest of annotations removed for conciseness @EnableBinding(Sink.class) #A public class LicenseServiceApplication { @StreamListener(Sink.INPUT) #B public void loggerSink(OrganizationChangeModel orgChange) { logger.debug("Received an {} event for organization id {}", orgChange.getAction(), orgChange.getOrganizationId()); } //Rest of the code removed for conciseness }Because the licensing service is a consumer of a message, we’re going to pass the
@EnableBindingannotation the valueSink.class. This tells Spring Cloud Stream to bind to a message broker using the default SpringSinkinterface. Similar to the Spring Cloud SteamSourceinterface described in section 10.3.1, Spring Cloud Stream exposes a default channel on the Sink interface. The channel on theSinkinterface is calledinputand is used to listen for incoming messages on a channel.