Challenge 3 - Dapr Pub/Sub Messaging

< Previous Challenge - Home - Next Challenge >

Introduction

In this challenge, you’re going to add Dapr publish/subscribe messaging to send messages from the TrafficControlService to the FineCollectionService.

Description

In challenge 2, you implemented direct, synchronous communication between two microservices. This pattern is common when an immediate response is required. Communication between services doesn’t always require an immediate response.

The publish/subscribe pattern allows your microservices to communicate asynchronously with each other purely by sending messages. In this system, the producer of a message sends it to a topic, with no knowledge of what service(s) will consume the message. A message can even be sent if there’s no consumer for it.

Similarly, a subscriber or consumer will receive messages from a topic without knowledge of what producer sent it. This pattern is especially useful when you need to decouple microservices from one another. See the diagram below for an overview of how this pattern works with Dapr:

You will need to modify the services to use the Dapr pub/sub building block.

Optional if re-implementing FineCollectionService using Dapr .NET SDK

Success Criteria

This challenge targets the operations labeled as number 2 in the end-state setup:

Tips

Specific info for using the Dapr .NET SDK for programmatic subscriptions (not needed unless implementing SpeedingViolation using Dapr .NET SDK)

Learning Resources