quickstarts/pub_sub/go/http
Paul Yuknewicz 574841045f
Merge pull request #986 from mikeee/bump-go-validation
bump go validation workflow to 1.21

(cherry picked from commit ec1e515512)
Signed-off-by: mikeee <hey@mike.ee>
2024-02-14 10:13:04 +00:00
..
checkout pub_sub: go: set publisher sleep to 1 second (#891) 2023-09-08 15:53:08 -07:00
order-processor go: update code to more modern version 2023-07-03 20:08:07 +02:00
README.md Merge pull request #986 from mikeee/bump-go-validation 2024-02-14 10:13:04 +00:00
dapr.yaml Merging `release-1.12` into main branch (#952) 2023-10-13 16:10:27 -07:00
makefile Removed docker image prefix addition step 2022-07-25 12:28:57 -07:00

README.md

Dapr pub/sub

In this quickstart, you'll create a publisher microservice and a subscriber microservice to demonstrate how Dapr enables a publish-subcribe pattern. The publisher generates messages for a specific topic, while the subscriber listen for messages in specific topics.

Check out the documentation about Dapr pubsub for more details.

Note: This example leverages HTTP requests only. You can find an example of using the Dapr Client SDK (recommended) in the sdk folder.

This quickstart includes one publisher: Go client message generator checkout.

And one subscriber: Go subscriber order-processor.

Run all apps with multi-app run template file:

This section shows how to run both applications at once using multi-app run template files with dapr run -f .. This enables to you test the interactions between multiple applications.

  1. Open a new terminal window and run the multi app run template:
dapr run -f .

The terminal console output should look similar to this:

== APP - checkout-http == Published data: {"orderId":1}
== APP - order-processor-http == Subscriber received: {"orderId":1}
== APP - checkout-http == Published data: {"orderId":2}
== APP - order-processor-http == Subscriber received: {"orderId":2}
== APP - checkout-http == Published data: {"orderId":3}
== APP - order-processor-http == Subscriber received: {"orderId":3}
== APP - checkout-http == Published data: {"orderId":4}
== APP - order-processor-http == Subscriber received: {"orderId":4}
== APP - checkout-http == Published data: {"orderId":5}
== APP - order-processor-http == Subscriber received: {"orderId":5}
== APP - checkout-http == Published data: {"orderId":6}
== APP - order-processor-http == Subscriber received: {"orderId":6}
== APP - checkout-http == Published data: {"orderId":7}
== APP - order-processor-http == Subscriber received: {"orderId":7}
== APP - checkout-http == Published data: {"orderId":8}
== APP - order-processor-http == Subscriber received: {"orderId":8}
== APP - checkout-http == Published data: {"orderId":9}
== APP - order-processor-http == Subscriber received: {"orderId":9}
== APP - checkout-http == Published data: {"orderId":10}
== APP - order-processor-http == Subscriber received: {"orderId":10}
  1. Stop and clean up application processes
dapr stop -f .

Run a single app at a time with Dapr (Optional)

An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple dapr run .. -- dotnet run commands. This next section covers how to do this.

Run Go message subscriber with Dapr

  1. Run the Go subscriber app with Dapr in the order-processor folder:
cd ./order-processor
dapr run --app-port 6007 --app-id order-processor-http --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- go run .

Run Go message publisher with Dapr

  1. Run the Go publisher app with Dapr in the checkout folder:
cd ./checkout
dapr run --app-id checkout-http --app-protocol http --dapr-http-port 3500 --resources-path ../../../components -- go run .

To stop:

dapr stop --app-id checkout-http
dapr stop --app-id order-processor