Exemple #1
0
        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();
                }
            }
        }
Exemple #2
0
        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();
            }
        }
        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("direct", durable: true, type: ExchangeType.Direct);

                    Array logNameArray = Enum.GetValues(typeof(LogNames));

                    for (int i = 1; i <= count; i++)
                    {
                        Random rnd = new Random();

                        LogNames log = (LogNames)logNameArray.GetValue(rnd.Next(logNameArray.Length));

                        var bodyByte = Encoding.UTF8.GetBytes($"{log.ToString()}");

                        var properties = channel.CreateBasicProperties();

                        properties.Persistent = true;

                        channel.BasicPublish("direct", log.ToString(), properties, bodyByte);

                        Console.WriteLine($"{log.ToString()}  * send!");
                    }
                }
            }
        }
Exemple #4
0
        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();
            }
        }