Exemplo n.º 1
0
        static Task PoolTestAsync()
        {
            var configManager   = CreateConfigurationManager();
            var senderFactory   = new AMQSenderFactory(new AMQConnectionFactory());
            var receiverFactory = new AMQReceiverFactory(new AMQConnectionFactory());
            var factory         = new AMQSenderReceiverFactory(senderFactory, receiverFactory);

            using (var amqPool = new AMQPoolAsync(configManager, factory, 5))
            {
                var tasks = new List <Task>();

                for (var i = 0; i < 10; i++)
                {
                    var task = Task.Run(async() =>
                    {
                        try
                        {
                            for (var j = 0; j < 10; j++)
                            {
                                using (var producer = await amqPool.GetAsync <IAMQSenderText>("defaultConnection", "MY_AMQ_TEST"))
                                {
                                    var message = $"message: {i * j}";
                                    await producer.Instance.SendAsync(message);

                                    Console.WriteLine($"{producer.PoolId} - {producer.Instance.Id} - {message}");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    });

                    tasks.Add(task);
                }

                Console.WriteLine("Waiting for Tasks to complete...");
                Task.WaitAll(tasks.ToArray());
                Console.WriteLine("Tasks completed.");

                return(Task.CompletedTask);
            }
        }
Exemplo n.º 2
0
        static void PoolTest()
        {
            var configManager   = CreateConfigurationManager();
            var senderFactory   = new AMQSenderFactory(new AMQConnectionFactory());
            var receiverFactory = new AMQReceiverFactory(new AMQConnectionFactory());
            var factory         = new AMQSenderReceiverFactory(senderFactory, receiverFactory);

            using (var amqPoole = new AMQPool(configManager, factory, 5))
            {
                for (var i = 0; i < 10; i++)
                {
                    var t = new Thread(PoolThreadTest1);
                    t.Start(new Tuple <AMQPool, int>(amqPoole, i));
                }

                Console.WriteLine("Waiting for Tasks to complete...");
                Console.ReadKey();
            }
        }