Messaging for Microservices with Spring Boot and RabbitMQ in real_time.docx

  • No School
  • AA 1
  • 34

This preview shows page 1 - 5 out of 34 pages.

Go Microservices, Messaging With RabbitMQ and AMQP Introduction Microservices is all about separating your application’s business domain into bounded contexts with clearly separated domains, running with process separation where any persistent relations across domain boundaries has to rely on eventual consistency rather than ACID-like transactions or foreign key constraints. A lot of these concepts comes from or has been inspired by Domain-driven design (DDD). That’s yet another huge topic one could write a blog series about. In the context of our Go microservice blog series and microservice architecture in general, one pattern for accomplishing loose coupling between services is to use messaging for inter-service communication that doesn’t need a strict request/response message interchange or similar. That said, using messaging is just one of many strategies one can adopt to facilitate loose coupling between services. For this part of the blog series, we’ll make our “accountservice” place a message on a RabbitMQ Exchange whenever a particular account object has been read. This message will be consumed by a brand new microservice we’ll write in this blog post. We’ll also deal with reusing Go code across multiple microservices by putting them in a “common” library we can import into each service. Remember the system landscape image from Part 1? Here’s an image of what it’ll look like after this part has been finished:
Image of page 1

Subscribe to view the full document.

There’s still a lot of stuff missing until we’re done. Don’t worry, we’ll get there. Source Code There will be a lot of new source code for this part and not all of it will be included in the blog text. For the complete source, clone and switch to the branch for part 9: git checkout P9 Sending a Message We’ll implement a simple make-believe use case: When certain “VIP” accounts are read in the “accountservice,” we want to notify a “VIP offer” service that under certain circumstances will generate an “offer” for the account holder. In a properly designed domain model, the accounts objects and VIP offer objects are two independent domains that should have as little knowledge of each other as possible.
Image of page 2
The accountservice should never access the storage of the VIP service (offers) directly. In this case, we’re passing a message to the “vipservice” over RabbitMQ fully delegating both business logic and persistence to the “vipservice.” We’ll do all communication using the AMQP protocol which is an ISO standardized application layer protocol for messaging geared for interoperability. Our Go library of choice for using AMQP is streadway/amqp , just like in part 8 when we consumed configuration updates. Let’s repeat how exchanges in AMQP relates to publishers , consumers , and queues :
Image of page 3

Subscribe to view the full document.

A message is published to an exchange , which then distributes message copies to queue(s) based on routing rules and bindings which may have registered consumers . Check this thread on Quora for a good explanation.
Image of page 4
Image of page 5
  • Fall '19

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes