1- using System . Text ;
21using RabbitMQ . Client ;
2+ using System . Text ;
33
44var factory = new ConnectionFactory { HostName = "localhost" } ;
5- using var connection = factory . CreateConnection ( ) ;
6- using var channel = connection . CreateModel ( ) ;
5+ using var connection = await factory . CreateConnectionAsync ( ) ;
6+ using var channel = await connection . CreateChannelAsync ( ) ;
77
8- channel . QueueDeclare ( queue : "task_queue" ,
9- durable : true ,
10- exclusive : false ,
11- autoDelete : false ,
12- arguments : null ) ;
8+ await channel . QueueDeclareAsync ( queue : "task_queue" , durable : true , exclusive : false ,
9+ autoDelete : false , arguments : null ) ;
1310
1411var message = GetMessage ( args ) ;
1512var body = Encoding . UTF8 . GetBytes ( message ) ;
1613
17- var properties = channel . CreateBasicProperties ( ) ;
18- properties . Persistent = true ;
14+ var properties = new BasicProperties
15+ {
16+ Persistent = true
17+ } ;
1918
20- channel . BasicPublish ( exchange : string . Empty ,
21- routingKey : "task_queue" ,
22- basicProperties : properties ,
23- body : body ) ;
19+ await channel . BasicPublishAsync ( exchange : string . Empty , routingKey : "task_queue" , mandatory : true ,
20+ basicProperties : properties , body : body ) ;
2421Console . WriteLine ( $ " [x] Sent { message } ") ;
2522
26- Console . WriteLine ( " Press [enter] to exit." ) ;
27- Console . ReadLine ( ) ;
28-
2923static string GetMessage ( string [ ] args )
3024{
3125 return ( ( args . Length > 0 ) ? string . Join ( " " , args ) : "Hello World!" ) ;
32- }
26+ }
0 commit comments