Skip to content

Commit 26a9330

Browse files
committed
first commit
0 parents  commit 26a9330

File tree

167 files changed

+26336
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+26336
-0
lines changed

MIT.md

Whitespace-only changes.

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Produce and Consume Messages with RabbitMQ using Node.js
2+
3+
This guide demonstrates how to produce and consume messages with RabbitMQ using Node.js and the `amqplib` library.
4+
5+
## Prerequisites
6+
7+
- Node.js installed on your system
8+
- RabbitMQ server running locally or accessible
9+
10+
## Installation
11+
12+
1. Clone this repository:
13+
14+
```sh
15+
git clone https://github.com/jmrashed/produce-consume-rabbitmq-nodejs.git
16+
```
17+
18+
2. Navigate to the project directory:
19+
20+
```bash
21+
cd produce-consume-rabbitmq-nodejs
22+
```
23+
24+
3. Install dependencies using npm:
25+
26+
```bash
27+
npm install
28+
```
29+
30+
# Usage
31+
32+
## Produce Messages
33+
34+
1. Open a terminal and navigate to the project directory.
35+
36+
2. Run the producer script to send a message to the RabbitMQ queue:
37+
38+
```bash
39+
node produce.js
40+
```
41+
42+
3. The producer will send a message to the queue. You should see an output similar to:
43+
44+
```bash
45+
Message sent: Hello, RabbitMQ!Your random number is 0.6063381710564761
46+
```
47+
48+
49+
50+
## Consume Messages
51+
52+
1. Open a terminal and navigate to the project directory.
53+
54+
2. Run the producer script to send a message to the RabbitMQ queue:
55+
56+
```bash
57+
node consume.js
58+
```
59+
60+
3. The producer will send a message to the queue. You should see an output similar to:
61+
62+
```bash
63+
Received message: Hello, RabbitMQ!Your random number is 0.6063381710564761
64+
```
65+
66+
67+
# Contributing
68+
Contributions are welcome! If you find a bug or want to add a new feature, please follow these steps:
69+
70+
Fork the repository.
71+
72+
Create a new branch: `git checkout -b feature/new-feature`.
73+
74+
Make changes and commit: `git commit -am 'Add new feature'`.
75+
76+
Push to the branch: `git push origin feature/new-feature`.
77+
78+
Create a pull request.
79+
80+
81+
# License
82+
This project is licensed under the [MIT License](MIT.md) - see the LICENSE file for details.

consume.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const amqp = require('amqplib');
2+
3+
const AMQP_URL = 'amqp://localhost'; // RabbitMQ server URL
4+
5+
async function consumeMessages() {
6+
try {
7+
const connection = await amqp.connect(AMQP_URL);
8+
const channel = await connection.createChannel();
9+
10+
const queueName = 'test_queue';
11+
12+
await channel.assertQueue(queueName);
13+
14+
console.log('Waiting for messages. To exit, press Ctrl+C.');
15+
16+
channel.consume(queueName, (message) => {
17+
if (message) {
18+
console.log(`Received message: ${message.content.toString()}`);
19+
channel.ack(message); // Acknowledge the message
20+
}
21+
});
22+
} catch (error) {
23+
console.error('Error consuming messages:', error);
24+
}
25+
}
26+
27+
consumeMessages();

node_modules/.package-lock.json

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@acuminous/bitsyntax/LICENSE

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@acuminous/bitsyntax/LICENSE-MIT

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@acuminous/bitsyntax/Makefile

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)