This repository contains a simple demo of Google Pub/Sub. Google Pub/Sub is a fully-managed real-time messaging service that allows you to send and receive messages between independent applications. It is a great tool for building distributed systems and microservices.
- Google Cloud SDK
- Python 3.9+
- Clone the repository:
git clone https://github.com/yourusername/google-pubsub-demo.git
cd google-pubsub-demo
- Install dependencies:
pip install -r requirements.txt
- Set up Google Cloud SDK:
Follow the instructions here to install and initialize the Google Cloud SDK.
- Set up Google Pub/Sub:
Follow the instructions here to create a topic and subscription.
-
Make sure you have created Google Service Account credentials and downloaded the JSON file. See here for more information.
-
Make sure you add roles
Pub/Sub Publisher
andPub/Sub Subscriber
to your service account. -
Before running the demo, please edit variables in
config.py
to match your project, topic, and subscription.
project_id = "your-project-id"
topic_id = "your-topic-id"
subscription_id = "your-subscription-id"
credentials_json_path = "your-credentials-file-path"
- Start the subscriber:
python src/subscriber.py
- Start the publisher and enter a message:
python src/publisher.py
Enter a message: Hello World!
- Check the subscriber terminal to see the message.
Received message: Hello World!
You should see messages being published and received in the console.