10 Event-driven applications and functions

 

This chapter covers:

  • Understanding event-driven architectures
  • Using RabbitMQ as the message broker
  • Leveraging functions with Spring Cloud Function
  • Processing events with Spring Cloud Stream
  • Producing and consuming events with Spring Cloud Stream

In previous chapters, you worked on a system of distributed applications interacting with each other according to the request/response pattern, a type of synchronous communication. You saw how to design the interaction both in an imperative and a reactive way. In the first case, the thread would block waiting for a response. In the second case, the thread would not wait, and the response would be processed by any available thread asynchronously once received.

Even if the reactive programming paradigm lets you subscribe to producers and process the incoming data asynchronously, the interaction between the two applications is synchronous. The first application (the client) sends a request to the second one (the server) and expects a response to arrive in a short time. How the client processes the response (imperative or reactive) is an implementation detail that doesn’t affect the interaction itself. No matter what, a response is expected to arrive.

Cloud native applications should be loosely coupled. The microservices expert Sam Newman identifies a few different types of coupling, including implementation, deployment, and temporal. Let’s consider the Polar Bookshop you’ve been working on so far.

10.1 Event-driven architectures

10.1.1 Understanding the event-driven models

10.1.2 Event-driven with pub/sub

10.2 Message brokers with RabbitMQ

10.2.1 Understanding AMQP for messaging systems

10.2.2 Using RabbitMQ for publish/subscribe communications

10.3 Functions with Spring Cloud Function

10.3.1 Using the functional paradigm in Spring Cloud Function

10.3.2 Composing and integrating functions: REST, serverless, data streams

10.3.3 Writing integration tests with @FunctionalSpringBootTest

10.4 Processing messages with Spring Cloud Stream

10.4.1 Configuring the integration with RabbitMQ

10.4.2 Binding functions to message channels

10.4.3 Writing integration tests with a Test Binder

10.4.4 Making messaging resilient to failures

10.5 Producing and consuming messages with Spring Cloud Stream

10.5.1 Implementing event consumers and the problem of idempotency

10.5.2 Implementing event producers and the problem of atomicity