This project implements a simple message queue service using Go. It provides endpoints for subscribing, unsubscribing, publishing messages, and retrieving messages.
Endpoint: POST /v1/subscribe
Description: Allows a subscriber to subscribe to one or more topics.
Request Parameters:
{
"endpoint": "http://subscriber-endpoint.com",
"topics": ["topic1", "topic2"]
}Request Body:
endpoint(string): The URL where the subscriber is located.topics(array of strings): List of topics to subscribe to.
Response:
-
Success:
{ "data": { "subscriber_id": "unique-subscriber-id" }, "message": "Subscribed successfully" } -
Error:
{ "error": "error-message" }
Endpoint: POST /v1/unsubscribe
Description: Allows a subscriber to unsubscribe from one or more topics.
Request Parameters:
{
"subscriber_id": "unique-subscriber-id",
"topics": ["topic1", "topic2"]
}Request Body:
subscriber_id(string): The ID of the subscriber to be removed.topics(array of strings): List of topics to unsubscribe from.
Response:
-
Success:
{ "message": "Unsubscribed successfully from the specified topics" } -
Error:
{ "error": "error-message" }
Endpoint: POST /v1/publish
Description: Publishes a message to a specified topic.
Request Parameters:
{
"topic": "topic1",
"message": "This is a test message"
}Request Body:
topic(string): The topic to which the message will be published.message(string): The content of the message.
Response:
-
Success:
{ "message": "Message published successfully to all topic subscribers" } -
Error:
{ "error": "error-message" }
Endpoint: GET /v1/retrieve
Description: Retrieves messages for a specific subscriber from a specified topic starting from a given date.
Request Parameters:
{
"topic": "topic1",
"subId": "unique-subscriber-id",
"startDate": "2024-01-01T00:00:00Z"
}Query Parameters:
topic(string): The topic from which messages will be retrieved.subId(string): The ID of the subscriber requesting the messages.startDate(string): The start date in RFC3339 format to filter messages from.
Response:
-
Success:
{ "data": [ { "ID": "message-id", "Body": "Message content", "PUBLISHED_AT": "2024-01-01T00:00:00Z", "CONSUMED_AT": "2024-01-01T01:00:00Z" } ] } -
Error:
{ "error": "error-message" }
-
Clone the repository:
git clone https://github.com/your-repo/Message-Queue.git
-
Navigate to the project directory:
cd Message-Queue -
Build and run the application:
go run . -
The server will start at port 3000.