-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
32 lines (30 loc) · 1.18 KB
/
Program.cs
File metadata and controls
32 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using RabbitMQTopic;
namespace ProducerApp
{
class Program
{
static void Main(string[] args)
{
var producer = new Producer(new ProducerSettings
{
AmqpUri = new Uri("amqp://demo:123456@localhost/test"),
ClientName = "ProducerApp",
SendMsgTimeout = 1000,
}, false);
producer.RegisterTopic("CommandTopic", 4, new string[] { string.Empty, "Group1" }).Start();
Console.WriteLine("Producer started!");
var random = new Random();
for (var i = 1; i <= 10; i++)
{
var messageId = Guid.NewGuid().ToString();
var routingKey = Guid.NewGuid().ToString();
var body = System.Text.Encoding.UTF8.GetBytes($"{i} delayed message {messageId}");
var topicMessage = new Message("CommandTopic", 1, body, "text/json", 1000 * random.Next(1, 5), tag: "System.String");
producer.SendMessage(topicMessage, routingKey);
}
producer.Shutdown();
Console.WriteLine("Producer shutdown!");
}
}
}