{"id":25845335,"url":"https://github.com/noahwillson/centralized-rabbitmq-example","last_synced_at":"2026-05-01T22:35:44.070Z","repository":{"id":279725955,"uuid":"939742688","full_name":"noahwillson/centralized-rabbitmq-example","owner":"noahwillson","description":"This repository demonstrates a centralized RabbitMQ microservices architecture using NestJS (TypeScript) and Fastify (JavaScript). It includes three main components: Centralized RabbitMQ Service, Publisher Microservice, Consumer Microservice.","archived":false,"fork":false,"pushed_at":"2025-02-27T03:19:58.000Z","size":126,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-27T04:23:58.944Z","etag":null,"topics":["fastify","microservices","nestjs","rabbitmq","rabbitmq-consumer","rabbitmq-producer","rabbitmq-server"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noahwillson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-27T03:11:27.000Z","updated_at":"2025-02-27T03:20:02.000Z","dependencies_parsed_at":"2025-02-27T04:28:58.609Z","dependency_job_id":"74f14c69-2d64-4102-945a-10b0e6348316","html_url":"https://github.com/noahwillson/centralized-rabbitmq-example","commit_stats":null,"previous_names":["noahwillson/centralized-rabbitmq-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/noahwillson/centralized-rabbitmq-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahwillson%2Fcentralized-rabbitmq-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahwillson%2Fcentralized-rabbitmq-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahwillson%2Fcentralized-rabbitmq-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahwillson%2Fcentralized-rabbitmq-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noahwillson","download_url":"https://codeload.github.com/noahwillson/centralized-rabbitmq-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahwillson%2Fcentralized-rabbitmq-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32515838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","microservices","nestjs","rabbitmq","rabbitmq-consumer","rabbitmq-producer","rabbitmq-server"],"created_at":"2025-03-01T08:18:34.457Z","updated_at":"2026-05-01T22:35:44.054Z","avatar_url":"https://github.com/noahwillson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Centralized RabbitMQ Microservices Architecture\n\n---\n\n## Features\n\n### Centralized RabbitMQ Service (NestJS)\n- **Publish Messages**: Accepts POST requests to publish messages to RabbitMQ exchanges/queues.\n- **Create Queues**: Provides endpoints to create queues and bind them to exchanges.\n- **Test Messages**: Includes a test endpoint for quick message publishing.\n- **Event Listener**: Automatically listens to and processes test events.\n\n### Publisher Microservice (Fastify)\n- **Publish Messages**: Sends messages to the Centralized RabbitMQ Service via HTTP requests.\n- **Batch Publishing**: Supports publishing multiple messages in a single request.\n- **Message Types**: Supports events, commands, and notifications.\n\n### Consumer Microservice (Fastify)\n- **Consume Messages**: Listens to queues and processes messages from the Centralized RabbitMQ Service.\n- **Error Handling**: Implements retry logic and dead-letter queues for failed messages.\n- **Custom Handlers**: Allows adding custom message handlers for different message types.\n\n---\n\n## Architecture Overview\n\n### Flow\n1. **Producer** (Fastify Microservice) sends a POST request to the **Centralized RabbitMQ Service** (NestJS).\n2. The Centralized Service publishes the message to RabbitMQ.\n3. The message is stored in a **queue** in RabbitMQ.\n4. The **Consumer** (Fastify Microservice) listens to the queue and processes the message.\n\n### Benefits\n- **Centralized Management**: All RabbitMQ operations are handled by a single service.\n- **Decoupling**: Microservices are decoupled from RabbitMQ configuration.\n- **Scalability**: The Centralized Service can be scaled independently.\n- **Consistency**: Ensures consistent message formatting and routing rules.\n\n---\n\n## Getting Started\n\n### Prerequisites\n- Node.js (v16 or higher)\n- RabbitMQ (Docker recommended)\n- Docker (optional, for RabbitMQ)\n\n### Installation\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/noahwillson/centralized-rabbitmq-microservices.git\n   cd centralized-rabbitmq-microservices\n   ```\n\n2. Install dependencies for each service:\n   ```bash\n   cd centralized-service \u0026\u0026 npm install\n   cd ../rabbitmq-publisher \u0026\u0026 npm install\n   cd ../rabbitmq-consumer \u0026\u0026 npm install\n   ```\n\n3. Start RabbitMQ using Docker:\n   ```bash\n   docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management\n   ```\n\n4. Configure environment variables:\n   - Create `.env` files in each service directory with the following content:\n     ```\n     RABBITMQ_URI=amqp://localhost:5672\n     PORT=3000  # For centralized-service\n     PORT=3001  # For rabbitmq-consumer\n     PORT=3002  # For rabbitmq-publisher\n     ```\n\n### Running the Services\n\n1. Start the Centralized RabbitMQ Service:\n   ```bash\n   cd centralized-service\n   npm run start\n   ```\n\n2. Start the Consumer Microservice:\n   ```bash\n   cd ../rabbitmq-consumer\n   npm run start\n   ```\n\n3. Start the Publisher Microservice:\n   ```bash\n   cd ../rabbitmq-publisher\n   npm run start\n   ```\n\n---\n\n## Usage\n\n### Publish a Message\n\nUse the Publisher Microservice to send a message:\n\n```bash\ncurl -X POST http://localhost:3002/events \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"type\": \"user.created\",\n    \"data\": {\n      \"userId\": \"123\",\n      \"username\": \"john_doe\",\n      \"email\": \"john@example.com\"\n    }\n  }'\n```\n\n### Create a Queue\n\nUse the Centralized Service to create a queue:\n\n```bash\ncurl -X POST http://localhost:3000/rabbitmq/create-queue \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"queueName\": \"user-events-queue\",\n    \"exchange\": \"events\",\n    \"routingKey\": \"user.#\"\n  }'\n```\n\n### Consume Messages\n\nThe Consumer Microservice automatically listens to the queue and processes messages. Check the logs to see the processed messages.\n\n---\n\n## Example Use Case\n\n### 1. Create a Queue and Bind it to an Exchange\n\n```bash\ncurl -X POST http://localhost:3000/rabbitmq/create-queue \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"queueName\": \"user-events-queue\",\n    \"exchange\": \"events\",\n    \"routingKey\": \"user.#\"\n  }'\n```\n\n### 2. Publish a Message\n\n```bash\ncurl -X POST http://localhost:3002/events \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"type\": \"user.created\",\n    \"data\": {\n      \"userId\": \"123\",\n      \"username\": \"john_doe\",\n      \"email\": \"john@example.com\"\n    }\n  }'\n```\n\n### 3. Process the Message\n\nThe Consumer Microservice processes the message and logs it:\n\n```\nReceived user event: {\n  type: 'user.created',\n  data: {\n    userId: '123',\n    username: 'john_doe',\n    email: 'john@example.com'\n  },\n  timestamp: '2023-05-15T12:34:56.789Z',\n  id: 'abcdef123456'\n}\nProcessing user event: {...}\n```\n\n---\n\n## Contributing\n\nContributions are welcome! Please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch (`git checkout -b feature/YourFeatureName`).\n3. Commit your changes (`git commit -m 'Add some feature'`).\n4. Push to the branch (`git push origin feature/YourFeatureName`).\n5. Open a pull request.\n\n---\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## Acknowledgments\n\n- [NestJS](https://nestjs.com/) for the centralized service.\n- [Fastify](https://www.fastify.io/) for the microservices.\n- [RabbitMQ](https://www.rabbitmq.com/) for message queuing.\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoahwillson%2Fcentralized-rabbitmq-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoahwillson%2Fcentralized-rabbitmq-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoahwillson%2Fcentralized-rabbitmq-example/lists"}