Exemplo n.º 1
0
        static int ReceiveFromNodeJS()
        {
            var factory = new ConnectionFactory()
            {
                HostName = _hostName
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: _exchangeName, type: "direct");
                    channel.QueueDeclare(_nodejsQueueName, true, false, false, arguments: null);
                    channel.QueueBind(queue: _nodejsQueueName, exchange: _exchangeName, routingKey: _routingKeyNodeQueue);

                    Console.WriteLine($"Waiting for messages from {_exchangeName} in queue {_nodejsQueueName} ...");

                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        var body       = ea.Body;
                        var message    = Encoding.UTF8.GetString(body);
                        var routingKey = ea.RoutingKey;
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        Console.WriteLine($"Received '{routingKey}': '{message}'");

                        QueueData qd = GetObjectFromJSONstring(message);

                        var mu = new MemoryUser(10000000);
                        qd.consumerRAMused = GC.GetTotalMemory(true) / 1024 / 1024;
                        SendDataToReturnQueue(qd);
                    };

                    channel.BasicConsume(queue: _nodejsQueueName, autoAck: true, consumer: consumer);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("Press [enter] to exit.");
                    Console.ReadLine();
                }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Exit");
            return(0);
        }
Exemplo n.º 2
0
        static int TestFunctions()
        {
            Console.WriteLine(" Hit 'S' for sender, or 'R' for receiver, or 'M' for high memory usage, or 'C' for high CPU usage:");
            var key = Console.ReadKey(true).Key;

            if (key == ConsoleKey.S)
            {
                SendDataToReturnQueue(new QueueData());
                return(0);
            }
            else if (key == ConsoleKey.R)
            {
                return(ReceiveFromReturnQueue());
            }
            else if (key == ConsoleKey.M)
            {
                var mu     = new MemoryUser(10000000);
                var memory = GC.GetTotalMemory(true) / 1024 / 1024;
                Console.WriteLine($"Memory used: {memory} MB");
                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
                return(0);
            }
            else if (key == ConsoleKey.C)
            {
                var cu         = new CPUtimeUser(5, Environment.ProcessorCount);
                var cpuCounter = new System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total", true);
                cpuCounter.NextValue();
                cu.StartStressCPU();
                var cpuUsagePercent = cpuCounter.NextValue();
                Console.WriteLine($"CPU used: {cpuUsagePercent} %");
                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
                return(0);
            }
            else
            {
                throw new ArgumentException("not supported: " + key);
            }
        }