static void Main(string[] args) { var factory = new ConnectionFactory(); factory.Uri = new Uri("amqps://*****:*****@fish.rmq.cloudamqp.com/tfmwqnnj"); using var connection = factory.CreateConnection(); var channel = connection.CreateModel(); channel.ExchangeDeclare("logs-topic", durable: true, type: ExchangeType.Topic); Enumerable.Range(1, 50).ToList().ForEach(x => { LogNames log1 = (LogNames) new Random().Next(1, 5); LogNames log2 = (LogNames) new Random().Next(1, 5); LogNames log3 = (LogNames) new Random().Next(1, 5); string message = $"Log Type: {log1}-{log2}-{log3}"; var messageBody = Encoding.UTF8.GetBytes(message); var routeKey = $"{log1}.{log2}.{log3}"; channel.BasicPublish("logs-topic", routeKey, null, messageBody); Console.WriteLine("Log has been sended: {0}", message); }); Console.ReadLine(); }
public static void Start() { var factory = new ConnectionFactory(); factory.Uri = new Uri("amqps://*****:*****@baboon.rmq.cloudamqp.com/avjbdlwa"); using var connection = factory.CreateConnection(); var channel = connection.CreateModel(); channel.ExchangeDeclare("Direct", durable: true, type: ExchangeType.Direct); Enum.GetNames(typeof(LogNames)).ToList().ForEach(x => { var queueName = $"direct-queue-{x}"; var routeKey = $"route-{x}"; channel.QueueDeclare(queueName, true, false, false); channel.QueueBind(queueName, "Direct", routeKey, null); }); for (int i = 1; i <= 100; i++) { LogNames log = (LogNames) new Random().Next(1, 4); var message = $"Log Type : {log}"; var messageBody = Encoding.UTF8.GetBytes(message); var routeKey = $"route-{log}"; Thread.Sleep(1); channel.BasicPublish("Direct", routeKey, null, messageBody); Console.WriteLine("Outgoing Message : " + message); } }
static void Main(string[] args) { var factory = new ConnectionFactory(); factory.HostName = "localhost"; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.ExchangeDeclare("topic-exchange", durable: true, type: ExchangeType.Topic); Array log_name_array = Enum.GetValues(typeof(LogNames)); for (int i = 1; i < 11; i++) { Random rnd = new Random(); LogNames log1 = (LogNames)log_name_array.GetValue(rnd.Next(log_name_array.Length)); LogNames log2 = (LogNames)log_name_array.GetValue(rnd.Next(log_name_array.Length)); LogNames log3 = (LogNames)log_name_array.GetValue(rnd.Next(log_name_array.Length)); string RoutingKey = $"{log1}.{log2}.{log3}"; var bodyByte = Encoding.UTF8.GetBytes($"log={log1.ToString()}-{log2.ToString()}-{log3.ToString()}"); var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish("topic-exchange", routingKey: RoutingKey, properties, body: bodyByte); Console.WriteLine($"log mesajı gönderilmiştir: mesaj ---> {RoutingKey.ToString()}"); } Console.ReadLine(); } } }
static void Main(string[] args) { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.ExchangeDeclare(exchange: "topic-exchange-log", durable: true, type: ExchangeType.Topic); Array logNameArrays = Enum.GetValues(typeof(LogNames)); for (int i = 1; i < 11; i++) { Random rnd = new Random(); LogNames log1 = (LogNames)logNameArrays.GetValue(rnd.Next(logNameArrays.Length)); LogNames log2 = (LogNames)logNameArrays.GetValue(rnd.Next(logNameArrays.Length)); LogNames log3 = (LogNames)logNameArrays.GetValue(rnd.Next(logNameArrays.Length)); string routingKey = $"{log1}.{log2}.{log3}"; var bodyByte = Encoding.UTF8 .GetBytes($"log = {log1.ToString()} - {log2.ToString()} - {log3.ToString()}"); //Direct exchange de routingkeyi direk alıyodum //Topic exchange de noktalı bir şekilde alcam var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish(exchange: "topic-exchange-log", routingKey: routingKey, basicProperties: properties, body: bodyByte); Console.WriteLine($"Log mesajı gönderilmiştir : mesaj -> {routingKey}"); } } Console.WriteLine("Çıkış yapmak için tıklayınız.."); Console.ReadLine(); } }
static void Main(string[] args) { //int count = int.Parse(args[1]); int count = 20; var factory = new ConnectionFactory(); factory.Uri = new Uri("amqps:"); //for local RabbitMq installation //factory.HostName = "localhost"; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.ExchangeDeclare("topic", durable: true, type: ExchangeType.Topic); Array logNameArray = Enum.GetValues(typeof(LogNames)); for (int i = 1; i <= count; i++) { Random rnd = new Random(); LogNames log1 = (LogNames)logNameArray.GetValue(rnd.Next(logNameArray.Length)); LogNames log2 = (LogNames)logNameArray.GetValue(rnd.Next(logNameArray.Length)); LogNames log3 = (LogNames)logNameArray.GetValue(rnd.Next(logNameArray.Length)); string routingKey = $"{log1.ToString()}.{log2.ToString()}.{log3.ToString()}"; var bodyByte = Encoding.UTF8.GetBytes($"log={routingKey}"); var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish("topic", routingKey, properties, bodyByte); Console.WriteLine($"{routingKey} * send!"); } } } }
static void Main(string[] args) { var factory = new ConnectionFactory(); factory.Uri = new Uri("amqps://*****:*****@fish.rmq.cloudamqp.com/tfmwqnnj"); using var connection = factory.CreateConnection(); var channel = connection.CreateModel(); // channel.QueueDeclare("first-queue", true, false, false); channel.ExchangeDeclare("logs-direct", durable: true, type: ExchangeType.Direct); Enum.GetNames(typeof(LogNames)).ToList().ForEach(x => { var queueName = $"direct-queue-{x}"; channel.QueueDeclare(queueName, true, false, false); var routeKey = $"route-{x}"; channel.QueueBind(queueName, "logs-direct", routeKey); }); Enumerable.Range(1, 50).ToList().ForEach(x => { LogNames log = (LogNames) new Random().Next(1, 5); string message = $"Log Type: {log}"; var messageBody = Encoding.UTF8.GetBytes(message); var routeKey = $"route-{log}"; channel.BasicPublish("logs-direct", routeKey, null, messageBody); Console.WriteLine("Log has been sended: {0}", message); }); Console.ReadLine(); }
static void Main(string[] args) { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { //Kanal oluşturduktan sonra exchangeime bir isim veriyorum. channel.ExchangeDeclare(exchange: "direct-exchange-log", durable: true, type: ExchangeType.Direct); Array logNameArrays = Enum.GetValues(typeof(LogNames)); for (int i = 1; i < 11; i++) { Random rnd = new Random(); LogNames log = (LogNames)logNameArrays.GetValue(rnd.Next(logNameArrays.Length)); var bodyByte = Encoding.UTF8.GetBytes($"log = {log.ToString()}"); var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish(exchange: "direct-exchange-log", routingKey: log.ToString(), basicProperties: properties, body: bodyByte); Console.WriteLine($"Log mesajı gönderilmiştir : {log.ToString()}"); } } Console.WriteLine("Çıkış yapmak için tıklayınız.."); Console.ReadLine(); } }