Пример #1
0
        public static void Main()
        {
            System.DateTime timeStart      = DateTime.UtcNow;
            var             conn           = new RabbitMQConnection("amqp://localhost");
            var             receiveChannel = new ReceiveChannel <int>(conn);

            Console.WriteLine(" Ready to go! ");
            receiveChannel.StartAsync(receiveFunc: async message =>
            {
                Console.WriteLine(" Try to [x] Received {0}", message);
                await Task.Delay(1);
                //try
                //{
                throw new Exception("Fail....");

                Console.WriteLine(" [x] Received {0}", message);
                //}
                //catch (Exception e)
                //{
                //    System.Console.WriteLine(e.Message + message);
                //    Console.WriteLine(" Fail to handle [x] Received {0}", message);
                //}
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
Пример #2
0
        public static void Main()
        {
            System.DateTime timeStart      = DateTime.UtcNow;
            var             conn           = new RabbitMQConnection("amqp://localhost");
            var             receiveChannel = new ReceiveChannel <int>(conn);

            receiveChannel.StartAsync(receiveFunc: async message =>
            {
                await Task.Delay(1);
                Console.WriteLine(" Try to [x] Received {0}", message);
                //try
                //{
                System.DateTime timeNow = DateTime.UtcNow;
                TimeSpan timeCount      = timeNow - timeStart;
                if (timeCount.TotalMilliseconds < 20000)
                {
                    //var x = 1 / (timeCount.Seconds - timeCount.Seconds);
                    //Console.WriteLine(x);
                    throw new Exception("Fail....");
                }

                Console.WriteLine(" [x] Received {0}", message);
                //}
                //catch (Exception e)
                //{
                //    System.Console.WriteLine(e.Message + message);
                //}
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
        /// <summary>
        /// Adds a receive channel that the gateway should listen to.
        /// </summary>
        /// <param name="address">The channel address.</param>
        /// <param name="maxConcurrency">Maximum number of receive connections. Default is `1`.</param>
        /// <param name="type">The channel type. Default is `http`.</param>
        /// <param name="isDefault">True if this should be the default channel for send operations. Default is `false`.</param>
        public void AddReceiveChannel(string address, string type = "http", int maxConcurrency = 1, bool isDefault = false)
        {
            Guard.AgainstNullAndEmpty(nameof(address), address);
            Guard.AgainstNullAndEmpty(nameof(type), type);
            Guard.AgainstNegativeAndZero(nameof(maxConcurrency), maxConcurrency);

            var channel = new ReceiveChannel
            {
                Address        = address,
                MaxConcurrency = maxConcurrency,
                Type           = type,
                Default        = isDefault
            };

            if (settings.TryGet(out List <ReceiveChannel> channels))
            {
                channels.Add(channel);
            }

            settings.Set <List <ReceiveChannel> >(new List <ReceiveChannel>
            {
                channel
            });
        }