Skip to content

Commit 4cad2ca

Browse files
committed
first example
1 parent 679a465 commit 4cad2ca

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

examples/index.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
const rabbit = require("rabbitmq-amqp-js-client")
1+
const rabbit = require("rabbitmq-amqp-js-client")
2+
3+
const queueName = "test-queue"
4+
5+
async function main() {
6+
const environment = rabbit.createEnvironment({
7+
host: "localhost",
8+
port: 5672,
9+
username: "rabbit",
10+
password: "rabbit",
11+
})
12+
13+
const connection = await environment.createConnection()
14+
15+
connection.management().declareQueue(queueName)
16+
17+
connection.createConsumer(queueName, { messageHandler: (message) => {
18+
console.log("received message", message.body)
19+
}})
20+
21+
const publisher = await connection.createPublisher({ queue: { name: queueName } })
22+
publisher.publish({ body: "message body"})
23+
24+
await sleep(2000)
25+
26+
await environment.close()
27+
}
28+
29+
main()
30+
.then(() => console.log("done!"))
31+
.catch((res) => {
32+
console.log("ERROR ", res)
33+
process.exit(-1)
34+
})
35+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { Management, AmqpManagement } from "./management.js"
2-
export { Environment, AmqpEnvironment } from "./environment.js"
2+
export { Environment, AmqpEnvironment, createEnvironment } from "./environment.js"
33
export { Connection, AmqpConnection } from "./connection.js"
44
export { Publisher, AmqpPublisher } from "./publisher.js"
55
export { Consumer, AmqpConsumer } from "./consumer.js"

0 commit comments

Comments
 (0)