Skip to main content

Quickstart: Publish/Subscribe

In this quickstart, you'll run a publisher and subscriber application on Diagrid Cloud. You will learn how to:

  • Provision a Diagrid project with a managed message broker using the Diagrid CLI.
  • Publish messages to a topic and receive them in a subscriber application using the Dapr Pub/Sub API.
  • Inspect published messages in the Diagrid Web Console.
Publisher and subscriber apps connected through Diagrid pub/subDiagridPublisher appApp IDpublisherMessage brokerApp IDsubscriberSubscriber app
Publisher and subscriber apps connected through Diagrid pub/subThe publisher sends a message through its App ID to the broker. Diagrid delivers it to the subscriber app through the subscriber's App ID.

1. Prerequisites​

Before you proceed, ensure you have the following prerequisites installed.

2. Log in to Diagrid​

Authenticate to Diagrid using the following command:

diagrid login

This command opens a new browser window where you'll be shown a confirmation code that should match the code in your terminal. Confirm the code, and if you're not logged into Diagrid, you'll be redirected to login.

Confirm your user details are correct using the following command:

diagrid whoami

The expected output contains the name of the organization, your user name, and the Diagrid API endpoint.

3. Clone Quickstart Code​

Clone the quickstart code from GitHub:

git clone https://github.com/diagridio/catalyst-quickstarts

Navigate to the quickstart directory:

cd catalyst-quickstarts/pubsub/python

4. Install Dependencies​

Install the dependencies for both the publisher and subscriber applications.

Install Python dependencies:

uv sync --all-packages

5. Run the application with Diagrid Cloud​

The diagrid dev run command creates your Diagrid project, provisions resources (apps, Diagrid Pub/Sub service and topic), configures environment variables, and launches your application connected to Diagrid Cloud.

uv run diagrid dev run -f pubsub-quickstart.yaml --project pubsub-quickstart --approve
tip

Wait a few seconds until you see the log: Connected App ID "publisher" to http://localhost:5001 and Connected App ID "subscriber" to http://localhost:5002 in the terminal before proceeding to ensure both applications are up and running.

6. Publish and receive a message​

With the quickstart running, test the Pub/Sub API by publishing a message and verifying it was received by the subscriber.

6.1 Publish a message​

Open a new terminal and execute the following command to publish an order message to the orders topic:

curl -i -X POST http://localhost:5001/order -H "Content-Type: application/json" -d '{"orderId":1}'

The expected response is:

HTTP/1.1 201 Created

In the diagrid dev run terminal, the publisher app logs should indicate a message was successfully published, and the subscriber app logs should show the message was received.

6.2 View in the Diagrid Web Console​

Open the Diagrid Cloud web console and navigate to the Pub/Sub topic explorer (under Resources > Managed Pub/Sub). When the Pending Message Count is 0, it means the subscriber app has successfully processed all messages on the orders topic.

Diagrid Pub/Sub topic explorer showing message delivery status

7. Clean Up​

Press CTRL+C in the terminal that runs diagrid dev run to stop the application and disconnect from Diagrid Cloud.

To delete the entire project and all provisioned resources:

diagrid project delete pubsub-quickstart

Summary​

In this quickstart you:

  • Logged in to Diagrid and provisioned a managed Pub/Sub project with a single CLI command (diagrid dev run).
  • Published a message to a topic and verified it was received by a subscriber application.
  • Inspected message delivery status using the Diagrid Pub/Sub topic explorer.

Diagrid handled message brokering, topic management, and delivery guarantees automatically — no infrastructure to manage.

Next steps​

Durable Execution & Dapr University · Learn this hands-onRunning Dapr applications with DiagridRun Dapr apps on Diagrid's managed pub/sub, KV store, and workflow engine — no infrastructure to operate.Beginner30 min.NET · Python · Java · JavaScriptStart the track Durable Execution & Dapr University · New to Dapr?Dapr 101: State Management, Service Invocation, and Pub/Sub APIsLearn Dapr's core building blocks — state management, service invocation, and pub/sub — through hands-on coding.Beginner45 min.NET · Python · Java · JavaScriptStart the track