firattamur / google-pub-sub-demo

This repository contains a simple demo of Google Pub/Sub.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Pub/Sub Demo

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.

Prerequisites

  • Google Cloud SDK
  • Python 3.9+

Setup

  1. Clone the repository:
git clone https://github.com/yourusername/google-pubsub-demo.git
cd google-pubsub-demo
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up Google Cloud SDK:

Follow the instructions here to install and initialize the Google Cloud SDK.

  1. Set up Google Pub/Sub:

Follow the instructions here to create a topic and subscription.

Running the Demo

  • 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 and Pub/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"
  1. Start the subscriber:
python src/subscriber.py
  1. Start the publisher and enter a message:
python src/publisher.py
Enter a message: Hello World!
  1. Check the subscriber terminal to see the message.
Received message: Hello World!

You should see messages being published and received in the console.

About

This repository contains a simple demo of Google Pub/Sub.


Languages

Language:Python 100.0%