File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 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 ) )
Original file line number Diff line number Diff line change 11export { Management , AmqpManagement } from "./management.js"
2- export { Environment , AmqpEnvironment } from "./environment.js"
2+ export { Environment , AmqpEnvironment , createEnvironment } from "./environment.js"
33export { Connection , AmqpConnection } from "./connection.js"
44export { Publisher , AmqpPublisher } from "./publisher.js"
55export { Consumer , AmqpConsumer } from "./consumer.js"
You can’t perform that action at this time.
0 commit comments