File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323 . Queue ( queueName )
2424 . MessageHandler ( ( ctx , message ) =>
2525 {
26- Console . WriteLine ( $ "Received a message: { Encoding . UTF8 . GetString ( message . Body ( ) ! ) } ") ;
26+ Console . WriteLine ( $ "Received a message: { message . BodyAsString ( ) } ") ;
2727 ctx . Accept ( ) ;
2828 return Task . CompletedTask ;
2929 } )
3838 {
3939 const string text = "hello" ;
4040 PublishResult pr = await publisher . PublishAsync ( new AmqpMessage ( Encoding . UTF8 . GetBytes ( text ) ) ) ;
41- if ( pr . Outcome . State == OutcomeState . Accepted )
42- {
43- Console . WriteLine ( "Confirmed" ) ;
44- }
45- else
46- {
47- Console . WriteLine ( $ "Unexpected outcome: { pr . Outcome . State } ") ;
41+ switch ( pr . Outcome . State ) {
42+ case OutcomeState . Accepted :
43+ Console . WriteLine ( $ " Accepted Message: { pr . Message . BodyAsString ( ) } confirmed") ;
44+ break ;
45+ case OutcomeState . Released : // here the message is not routed
46+ Console . WriteLine ( $ " Released Message: { pr . Message . BodyAsString ( ) } Released") ;
47+ break ;
48+ case OutcomeState . Rejected : // here there is also the error: `pr.Outcome.Error`
49+ Console . WriteLine ( $ "[Publisher] Message: { pr . Message . BodyAsString ( ) } Rejected with error: { pr . Outcome . Error } ") ;
50+ break ;
4851 }
4952
5053 await Task . Delay ( 500 ) ;
Original file line number Diff line number Diff line change 2828 Console . WriteLine ( $ " [x] Requesting fib({ iStr } )") ;
2929 IMessage request = new AmqpMessage ( Encoding . UTF8 . GetBytes ( iStr ) ) ;
3030 IMessage reply = await requester . PublishAsync ( request ) ;
31- string response = Encoding . UTF8 . GetString ( reply . Body ( ) ! ) ;
31+ string response = reply . BodyAsString ( ) ;
3232 Console . WriteLine ( $ " [.] Got '{ response } '") ;
3333 }
3434 }
Original file line number Diff line number Diff line change 2929 string response = "" ;
3030 try
3131 {
32- string message = Encoding . UTF8 . GetString ( request . Body ( ) ! ) ;
32+ string message = request . BodyAsString ( ) ;
3333 int n = int . Parse ( message ) ;
3434 Console . WriteLine ( $ " [.] fib({ message } )") ;
3535 response += Fib ( n ) ;
Original file line number Diff line number Diff line change 1- using System . Text ;
2- using RabbitMQ . AMQP . Client ;
1+ using RabbitMQ . AMQP . Client ;
32using RabbitMQ . AMQP . Client . Impl ;
43
54const string brokerUri = "amqp://guest:guest@localhost:5672/%2f" ;
2221 . Queue ( "hello" )
2322 . MessageHandler ( ( ctx , message ) =>
2423 {
25- Console . WriteLine ( $ "Received a message: { Encoding . UTF8 . GetString ( message . Body ( ) ! ) } ") ;
24+ Console . WriteLine ( $ "Received a message: { message . BodyAsString ( ) } ") ;
2625 ctx . Accept ( ) ;
2726 return Task . CompletedTask ;
2827 } )
Original file line number Diff line number Diff line change 1- using System . Text ;
2- using RabbitMQ . AMQP . Client ;
1+ using RabbitMQ . AMQP . Client ;
32using RabbitMQ . AMQP . Client . Impl ;
43
54const string brokerUri = "amqp://guest:guest@localhost:5672/%2f" ;
3332 . Queue ( queueName )
3433 . MessageHandler ( ( ctx , message ) =>
3534 {
36- string body = Encoding . UTF8 . GetString ( message . Body ( ) ! ) ;
35+ string body = message . BodyAsString ( ) ;
3736 Console . WriteLine ( $ " [x] Received '{ body } '") ;
3837 ctx . Accept ( ) ;
3938 return Task . CompletedTask ;
Original file line number Diff line number Diff line change 1- using System . Text ;
2- using RabbitMQ . AMQP . Client ;
1+ using RabbitMQ . AMQP . Client ;
32using RabbitMQ . AMQP . Client . Impl ;
43
54const string brokerUri = "amqp://guest:guest@localhost:5672/%2f" ;
4241 . Queue ( queueName )
4342 . MessageHandler ( ( ctx , message ) =>
4443 {
45- string body = Encoding . UTF8 . GetString ( message . Body ( ) ! ) ;
44+ string body = message . BodyAsString ( ) ;
4645 string routingKey = RoutingKey ( message ) ;
4746 Console . WriteLine ( $ " [x] Received '{ routingKey } ':'{ body } '") ;
4847 ctx . Accept ( ) ;
Original file line number Diff line number Diff line change 1- using System . Text ;
2- using RabbitMQ . AMQP . Client ;
1+ using RabbitMQ . AMQP . Client ;
32using RabbitMQ . AMQP . Client . Impl ;
43
54const string brokerUri = "amqp://guest:guest@localhost:5672/%2f" ;
4241 . Queue ( queueName )
4342 . MessageHandler ( ( ctx , message ) =>
4443 {
45- string body = Encoding . UTF8 . GetString ( message . Body ( ) ! ) ;
44+ string body = message . BodyAsString ( ) ;
4645 string routingKey = RoutingKey ( message ) ;
4746 Console . WriteLine ( $ " [x] Received '{ routingKey } ':'{ body } '") ;
4847 ctx . Accept ( ) ;
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ async Task RunServerAsync(CancellationToken cancellationToken)
6464 . RequestQueue ( requestQueue )
6565 . Handler ( ( ctx , request ) =>
6666 {
67- string payload = Encoding . UTF8 . GetString ( request . Body ( ) ! ) ;
67+ string payload = request . BodyAsString ( ) ;
6868 object ? mid = request . MessageId ( ) ;
6969 if ( mid != null )
7070 {
@@ -140,7 +140,7 @@ async Task RunClientAsync(CancellationToken cancellationToken)
140140 continue ;
141141 }
142142
143- string payload = Encoding . UTF8 . GetString ( reply . Body ( ) ! ) ;
143+ string payload = reply . BodyAsString ( ) ;
144144 Console . WriteLine ( $ "RPC Client: Sent ping request ({ requestId } )") ;
145145 Console . WriteLine ( $ "RPC Client: Received reply - { payload } ") ;
146146 }
Original file line number Diff line number Diff line change 1- using System . Text ;
2- using RabbitMQ . AMQP . Client ;
1+ using RabbitMQ . AMQP . Client ;
32using RabbitMQ . AMQP . Client . Impl ;
43
54const string brokerUri = "amqp://guest:guest@localhost:5672/%2f" ;
2423 . InitialCredits ( 1 )
2524 . MessageHandler ( ( ctx , message ) =>
2625 {
27- string body = Encoding . UTF8 . GetString ( message . Body ( ) ! ) ;
26+ string body = message . BodyAsString ( ) ;
2827 Console . WriteLine ( $ " [x] Received '{ body } '") ;
2928 try
3029 {
You can’t perform that action at this time.
0 commit comments