9 Messaging and event streaming with Vert.x

 

This chapter covers

  • Messaging with AMQP
  • Event streaming with Apache Kafka
  • Sending emails
  • Integration testing with messaging and event-streaming middleware

Reactive applications are a good fit for messaging and event-streaming technologies. So far we have mostly looked at services that expose HTTP APIs. But although HTTP is a versatile and effective protocol for interacting with a service, it should not be the only choice.

There are several options for integrating Vert.x-based services using messaging and event streaming. This chapter introduces AMQP message brokers and Apache Kafka. We will also discuss sending email using an SMTP server.

In this chapter we’ll dive into the implementation of the ingester and congratulation services. The ingester receives step updates from devices over HTTP and AMQP, and it forwards them into the system as Kafka events. The congratulation service listens for certain Kafka events to spot when a user has reached 10,000 steps in a day, and it sends a congratulation email.

9.1 Event-driven services beyond HTTP with Vert.x

HTTP is a sensible choice as a networked interface for an event-driven service, especially when a service offers an API. Messaging and event-streaming middleware offer useful tools for decoupling and integrating services. They are also typically better suited than HTTP for exchanging lots of events between services.

9.1.1 What Vert.x provides

9.1.2 The middleware and services that we’ll use

9.1.3 What is AMQP (and a message broker)?

9.1.4 What is Kafka?

9.2 Reliably ingesting messages over HTTP and AMQP

9.2.1 Ingesting from AMQP

9.2.2 Translating AMQP messages to Kafka records

9.2.3 Ingesting from HTTP

9.3 Sending congratulation emails

9.3.1 Listening for daily step update events

9.3.2 Sending emails

9.4 Integration tests