@@ -18,24 +18,23 @@ async function main() {
1818
1919 console . log ( ' [x] Requesting fib(%d)' , num ) ;
2020
21- // Consume from the Direct Reply-to pseudo-queue (noAck is mandatory)
22- channel . consume ( 'amq.rabbitmq.reply-to' , function ( msg ) {
23- if ( msg . properties . correlationId === correlationId ) {
24- console . log ( ' [.] Got %s' , msg . content . toString ( ) ) ;
25- setTimeout ( function ( ) {
26- connection . close ( ) ;
27- process . exit ( 0 ) ;
28- } , 500 ) ;
29- }
30- } , {
31- noAck : true
21+ const result = await new Promise ( ( resolve ) => {
22+ // Consume from the Direct Reply-to pseudo-queue (noAck is mandatory)
23+ channel . consume ( 'amq.rabbitmq.reply-to' , ( msg ) => {
24+ if ( msg . properties . correlationId === correlationId ) {
25+ resolve ( msg . content . toString ( ) ) ;
26+ }
27+ } , { noAck : true } ) ;
28+
29+ channel . sendToQueue ( 'rpc_queue' ,
30+ Buffer . from ( num . toString ( ) ) , {
31+ correlationId : correlationId ,
32+ replyTo : 'amq.rabbitmq.reply-to'
33+ } ) ;
3234 } ) ;
3335
34- channel . sendToQueue ( 'rpc_queue' ,
35- Buffer . from ( num . toString ( ) ) , {
36- correlationId : correlationId ,
37- replyTo : 'amq.rabbitmq.reply-to'
38- } ) ;
36+ console . log ( ' [.] Got %s' , result ) ;
37+ await connection . close ( ) ;
3938}
4039
4140function generateUuid ( ) {
0 commit comments