concept message broker in category spring

appears as: message brokers, message broker, messaging broker
Spring Microservices in Action, 2E MEAP V07

This is an excerpt from Manning's book Spring Microservices in Action, 2E MEAP V07.

  • 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 @EnableBinding annotation tells Spring Cloud Stream that we want to bind the service to a message broker. The use of Source.class in the @EnableBinding annotation tells Spring Cloud Stream that this service will communicate with the message broker via a set of channels defined on the Source class. 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 @EnableBinding annotation. The difference between the licensing service and the organization service is the value we’re going to pass to the @EnableBinding annotation, 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 @EnableBinding annotation the value Sink.class. This tells Spring Cloud Stream to bind to a message broker using the default Spring Sink interface. Similar to the Spring Cloud Steam Source interface described in section 10.3.1, Spring Cloud Stream exposes a default channel on the Sink interface. The channel on the Sink interface is called input and is used to listen for incoming messages on a channel.

    sitemap

    Unable to load book!

    The book could not be loaded.

    (try again in a couple of minutes)

    manning.com homepage
    test yourself with a liveTest