Spring Cloud Stream - A business scenario use case

Business scenario for these applications

The scenario is a cell phone company creating bills for its customers. Each call made by a user has a duration and an amount of data used during the call. As part of the process to generate a bill, the raw call data needs to be converted to a cost for the duration of the call and a cost for the amount of data used.

The three streaming applications are as follows:

The Source application named UsageDetailSender generates the users’ call duration and the amount of data used for each userId and sends a message that contains the UsageDetail object as JSON. The Processor application named UsageCostProcessor consumes the UsageDetail and computes the cost of the call and the cost of the data per userId. It sends the UsageCostDetail object as JSON. The Sink application named UsageCostLogger consumes the UsageCostDetail object and logs the cost of the call and data.

Message flow

When you deploy these three applications (UsageDetailSender, UsageCostProcessor, and UsageCostLogger), the flow of message is as follows:

UsageDetailSender -> UsageCostProcessor -> UsageCostLogger

The UsageDetailSender source application’s output is connected to the UsageCostProcessor processor application’s input. The UsageCostProcessor application’s output is connected to the UsageCostLogger sink application’s input.

When these applications run, the RabbitMQ binder binds the applications’ output and input boundaries into the corresponding exchanges and queues at RabbitMQ message broker.

Running the applications

Start each of them by using mvn spring-boot:run. The port number to be used by each of them is specified in their application.yml file.

Tags

  1. Stream Processing with Apache Kafka
  2. Stream Processing with RabbitMQ

Links to this note