|
2 | 2 | using RabbitMQ.Client.Events;
|
3 | 3 | using System.Text;
|
4 | 4 |
|
| 5 | +const string QUEUE_NAME = "rpc_queue"; |
| 6 | + |
5 | 7 | var factory = new ConnectionFactory { HostName = "localhost" };
|
6 | 8 | using var connection = await factory.CreateConnectionAsync();
|
7 | 9 | using var channel = await connection.CreateChannelAsync();
|
8 | 10 |
|
9 |
| -await channel.QueueDeclareAsync(queue: "rpc_queue", durable: false, exclusive: false, |
| 11 | +await channel.QueueDeclareAsync(queue: QUEUE_NAME, durable: false, exclusive: false, |
10 | 12 | autoDelete: false, arguments: null);
|
11 | 13 |
|
12 | 14 | await channel.BasicQosAsync(prefetchSize: 0, prefetchCount: 1, global: false);
|
13 | 15 |
|
14 | 16 | var consumer = new AsyncEventingBasicConsumer(channel);
|
15 |
| -await channel.BasicConsumeAsync("rpc_queue", false, consumer); |
16 |
| -Console.WriteLine(" [x] Awaiting RPC requests"); |
17 |
| - |
18 | 17 | consumer.Received += async (object sender, BasicDeliverEventArgs ea) =>
|
19 | 18 | {
|
20 |
| - IChannel ch = (IChannel)sender; |
| 19 | + AsyncEventingBasicConsumer cons = (AsyncEventingBasicConsumer)sender; |
| 20 | + IChannel ch = cons.Channel; |
21 | 21 | string response = string.Empty;
|
22 | 22 |
|
23 | 23 | byte[] body = ea.Body.ToArray();
|
@@ -48,6 +48,8 @@ await ch.BasicPublishAsync(exchange: string.Empty, routingKey: props.ReplyTo!,
|
48 | 48 | }
|
49 | 49 | };
|
50 | 50 |
|
| 51 | +await channel.BasicConsumeAsync(QUEUE_NAME, false, consumer); |
| 52 | +Console.WriteLine(" [x] Awaiting RPC requests"); |
51 | 53 | Console.WriteLine(" Press [enter] to exit.");
|
52 | 54 | Console.ReadLine();
|
53 | 55 |
|
|
0 commit comments