コード例 #1
0
ファイル: Program.cs プロジェクト: JohnEffo/EasyNetQ
        public static void Main(string[] args)
        {
            var logger = new NoDebugLogger();

            var bus = RabbitHutch.CreateBus("host=localhost",
                x => x.Register<IEasyNetQLogger>(_ => logger));

            int messageCount = 0;
            var timer = new Timer(state =>
            {
                Console.Out.WriteLine("messages per second = {0}", messageCount);
                Interlocked.Exchange(ref messageCount, 0);
            }, null, 1000, 1000);

            bus.Subscribe<TestPerformanceMessage>("consumer", message => Interlocked.Increment(ref messageCount));

            Console.CancelKeyPress += (source, cancelKeyPressArgs) =>
            {
                Console.Out.WriteLine("Shutting down");
                bus.Dispose();
                timer.Dispose();
                Console.WriteLine("Shut down complete");
            };

            Thread.Sleep(Timeout.Infinite);
        }
        public Task Run(CancellationToken cancellationToken)
        {
            var logger = new NoDebugLogger();

            bus = RabbitHutch.CreateBus("host=localhost;product=consumer",
                                        x => x
                                        .Register <IEasyNetQLogger>(_ => logger)
                                        .Register <IConventions, SingleQueueNamingConvention>()
                                        .Register <IHandlerCollectionFactory, HandlerCollectionPerQueueFactory>()
                                        );

            bus.SubscribeAsync <MessageA>("multiple", async m => await Task.Run(() => logger.InfoWrite("{0}", m)).ConfigureAwait(false));
            bus.SubscribeAsync <MessageB>("multiple", async m => await Task.Run(() => logger.InfoWrite("{0}", m)).ConfigureAwait(false));

            for (int i = 0; i < 100; i++)
            {
                bus.Publish(new MessageA());
                bus.Publish(new MessageB());
            }

            Console.WriteLine("press enter to exit");
            Console.ReadLine();

            return(Task.FromResult(0));
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            var logger = new NoDebugLogger();

            var bus = RabbitHutch.CreateBus("host=localhost",
                                            x => x.Register <IEasyNetQLogger>(_ => logger));

            int messageCount = 0;
            var timer        = new Timer(state =>
            {
                Console.Out.WriteLine("messages per second = {0}", messageCount);
                Interlocked.Exchange(ref messageCount, 0);
            }, null, 1000, 1000);

            bus.Subscribe <TestPerformanceMessage>("consumer", message => Interlocked.Increment(ref messageCount));

            Console.CancelKeyPress += (source, cancelKeyPressArgs) =>
            {
                Console.Out.WriteLine("Shutting down");
                bus.Dispose();
                timer.Dispose();
                Console.WriteLine("Shut down complete");
            };

            Thread.Sleep(Timeout.Infinite);
        }
コード例 #4
0
        public Task Run(CancellationToken cancellationToken)
        {
            var logger = new NoDebugLogger();

            bus = RabbitHutch.CreateBus("host=localhost;product=consumer",
                                        x => x.Register <IEasyNetQLogger>(_ => logger));

            int messageCount = 0;

            timer = new Timer(state =>
            {
                Console.Out.WriteLine("messages per second = {0}", messageCount);
                Interlocked.Exchange(ref messageCount, 0);
            }, null, 1000, 1000);

            bus.Subscribe <TestPerformanceMessage>("consumer", message => Interlocked.Increment(ref messageCount));

            Console.WriteLine("press enter to exit");
            Console.ReadLine();

            return(Task.FromResult(0));
        }