This project demonstrates how to use Azure Service Bus to publish
and subscribe
the messages using two different method:
connection_string_based
passwordless authentication
.
Azure Service Bus offers three pricing tiers
. For this project, the Premium
tier was selected due to its support for a maximum message size of 100MB
.
- Different message size was published & subscribed
[1MB, 10MB, 95MB, 100MB]
- Python
3.8
or higher pip
(Python package installer)- An
Azure account
with an active subscription
Clone
the repository:
git clone https://github.com/Mazhar004/azure-service-bus-pub-sub.git
Create a .env
file in the root of your project & insert your secrets. Here's an example:
FULLY_QUALIFIED_NAMESPACE=YOUR_SERVICE_BUS_NAME.servicebus.windows.net
# Required Connection String Based Configuration
CONNECTION_STR=
# Required for Password Less Configuration
AZURE_CLIENT_ID=
AZURE_CLIENT_SECRET=
AZURE_TENANT_ID=
# Required for Publisher & Subscriber
TOPIC_NAME=
# Required for Subscriber Only
SUBSCRIPTION_NAME=
-
Create a
virtual
environment:python3 -m venv venv
-
Activate the
virtual
environment:-
On
Unix
orMacOS
:source venv/bin/activate
-
-
Upgrade
pip
:pip install --upgrade pip setuptools
-
Install
the required packages:pip install -r requirements.txt
-
Install
Azure CLI
:For
Linux
:- Follow the guidline Link
For
macOS
:brew update && brew install azure-cli
-
Login to
Azure
:az login
To publish a message, run the following command:
python publisher.py --msg "Your message here" --pubsub
To start the subscriber, run the following command:
python subscriber.py
- Create a
.env
file in the root of your project & insert your secrets Sample Configuration
docker build -t pubsubapp .
- Subcriber
docker run pubsubapp python subscriber.py
- Publisher
docker run pubsubapp python publisher.py --msg "your msg" --pubsub
This project is licensed under the terms of the LICENSE file.