This project implements a simple Publisher-Subscriber Notification System using Node.js for the backend and React.js for the frontend.
- Subscribe to a Topic: Subscribers can subscribe to a topic.
- Notify Subscribers: Send notifications to all subscribers of a topic.
- Unsubscribe from a Topic: Subscribers can unsubscribe from a topic.
The backend is implemented using Node.js and Express.
-
Subscribe
- Endpoint:
/subscribe
- Method:
POST
- Body:
{ "topicId": "string", "subscriberId": "string" }
- Description: Adds a subscriber to a topic.
- Endpoint:
-
Notify
- Endpoint:
/notify
- Method:
POST
- Body:
{ "topicId": "string" }
- Description: Sends notifications to all subscribers of a topic.
- Endpoint:
-
Unsubscribe
- Endpoint:
/unsubscribe
- Method:
POST
- Body:
{ "topicId": "string", "subscriberId": "string" }
- Description: Removes a subscriber from a topic.
- Endpoint:
-
JavaScript Object (
topics
): Stores topics and their corresponding subscribers.- Key:
topicId
(string) - Value:
Set
ofsubscriberId
s (Set of strings)
- Key:
-
Set: Ensures unique subscribers for each topic.
- Non-existent Topic Notification: Attempting to notify subscribers of a non-existent topic returns a 404 error.
- Duplicate Subscription: Subscribing a subscriber to a topic they are already subscribed to does not create duplicate entries due to the use of a
Set
. - Unsubscribe Non-existent Subscriber: Attempting to unsubscribe a subscriber who is not subscribed to the topic returns a 404 error.
The frontend is implemented using React.js.
- Subscribe: Enter a topic ID and subscriber ID to subscribe to a topic.
- Notify: Enter a topic ID to notify all subscribers.
- Unsubscribe: Enter a topic ID and subscriber ID to unsubscribe from a topic.
- Navigate to the
pubsub-system
directory. - Install the required packages:
npm install express body-parser cors axios
- Start the backend server:
node index.js
- Navigate to the
pubsub-client
directory. - Install the required packages:
npm install
- Start the React development server:
npm start
- Ensure the backend server is running.
- Run the driver script to demonstrate the flow of the application:
node driver_functionn.js
- Subscribe
subscriber1
andsubscriber2
totopic1
. - Notify subscribers of
topic1
. - Unsubscribe
subscriber1
fromtopic1
. - Notify subscribers of
topic1
after unsubscription.
The driver script will output the results of each operation.
## Postman Documentation
The API endpoints for the Publisher-Subscriber Notification System are documented in Postman. You can import the collection to view and test the endpoints.
If the shareable link is not available, you can import the Postman collection using the JSON file included in the repository.
- Download the
PubSubSystem.postman_collection.json
file from the repository. - Open Postman and click on
Import
in the top left. - Select the
Upload Files
tab. - Choose the downloaded JSON file and click
Import
.
This will import all the API endpoints into your Postman workspace.
You Can also find shared valid json config for postman collection which is uploaded on repo along with code
### Screenshots
This project demonstrates a simple implementation of a Publisher-Subscriber Notification System using Node.js and React.js. The internal data structures ensure efficient and correct handling of subscriptions, notifications, and unsubscriptions.