This project is an in-memory Pub/Sub (Publish/Subscribe) message broker implemented in Go (Golang). The broker supports a fan-out model for topic-based message delivery, ensuring that messages published to a topic are delivered to all subscribers of that topic. Communication with the message broker is facilitated through a REST API, making it accessible and easy to integrate with other services.
Go version 1.23.1 or higher.
- Clone the repository:
git clone https://github.com/rsc1102/PubSub-Go.git
- Install dependencies:
go mod tidy
- Run the application:
go run main.go
The message broker provides the following REST API endpoints:
GET /ping
: ReturnsPONG
if server is active.POST /topics
: Creates a topic.- JSON schema:
{ "topic" : "topic1"}
- JSON schema:
DELETE /topics
: Deletes a topic- JSON schema:
{ "topic" : "topic1"}
- JSON schema:
GET /topics
: Returns all topicsPOST /subscriptions
: Creates a subscription for a topic.- JSON schema:
{ "topic": "topic1", "subscription": "alpha" }
- JSON schema:
DELETE /subscriptions
: Deletes a subscription for a topic.- JSON schema:
{ "topic": "topic1", "subscription": "alpha" }
- JSON schema:
GET /subscriptions
: Returns all subscriptions for a topic if it is provided, else returns all subscriptions for all topics.POST /publish
: Publishes message to a topic.- JSON schema:
{ "topic": "topic1", "content": "msg" }
- JSON schema:
POST /consume
: Consumes a message from a subscription.- JSON schema:
{ "topic": "topic1", "subscription": "alpha" }
- JSON schema:
.
├── go.mod # Module definition file
├── go.sum # Dependency checksum file
├── main.go # Entry point of the application
├── api/handlers/ # Contains API handler
│ └── handler.go # API handler
└── internal/services/ # Contains internal service logic
└── service.go # Service implementation