File tree Expand file tree Collapse file tree 1 file changed +21
-12
lines changed Expand file tree Collapse file tree 1 file changed +21
-12
lines changed Original file line number Diff line number Diff line change 3
3
var amqp = require ( 'amqplib' ) ;
4
4
var when = require ( 'when' ) ;
5
5
6
- amqp . connect ( 'amqp://localhost' ) . then ( function ( conn ) {
7
- return when ( conn . createChannel ( ) . then ( function ( ch ) {
6
+ var conn = amqp . connect ( 'amqp://localhost' ) ;
7
+ var ch = conn . then ( createChannel ) . then ( null , console . warn ) ;
8
8
9
- var q = 'hello' ;
10
- var ok = ch . assertQueue ( q , { durable : false } ) ;
11
-
12
- return ok . then ( function ( _qok ) {
13
- var msg = 'Hello World!' ;
14
- ch . sendToQueue ( q , new Buffer ( msg ) ) ;
15
- console . log ( " [x] Sent '%s'" , msg ) ;
16
- return ch .
8000
span>close ( ) ;
9
+ function createChannel ( conn ) {
10
+ return when (
11
+ conn . createChannel ( ) .
12
+ then ( sendMessage ) ) .
13
+ ensure ( function ( ) {
14
+ conn . close ( ) ;
17
15
} ) ;
18
- } ) ) . ensure ( function ( ) { conn . close ( ) ; } ) ;
19
- } ) . then ( null , console . warn ) ;
16
+ }
17
+
18
+ function sendMessage ( ch ) {
19
+ var q = 'hello' ;
20
+ var ok = ch . assertQueue ( q , { durable : false } ) ;
21
+
22
+ return ok . then ( function ( _ignore ) {
23
+ var msg = 'Hello World!' ;
24
+ ch . sendToQueue ( q , new Buffer ( msg ) ) ;
25
+ console . log ( " [x] Sent '%s'" , msg ) ;
26
+ return ch . close ( ) ;
27
+ } ) ;
28
+ }
You can’t perform that action at this time.
0 commit comments