示例#1
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _consumer = new MyConsumer(GetTask <ConsumeContext <PingMessage> >());

            configurator.UseScheduledRedelivery(r => r.Intervals(1000, 2000));
            configurator.Consumer(() => _consumer);
        }
    static void Main(string[] args)
    {
        var factory = new ConnectionFactory()
        {
            Uri = "amqp://*****:*****@lemur.cloudamqp.com/xxx"
        };

        using (var connection = factory.CreateConnection())
        {
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare("hello", false, false, false, null);
                var    consumer = new MyConsumer(channel);
                String tag      = channel.BasicConsume("hello", true, consumer);
                Console.WriteLine(" [*] Waiting for messages." +
                                  " any key to exit");
                Console.ReadLine();
                channel.BasicCancel(tag);


                /*while (true)
                 * {
                 * /////// DON'T USE THIS
                 * var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                 * var body = ea.Body;
                 * var message = Encoding.UTF8.GetString(body);
                 * Console.WriteLine(" [x] Received {0}", message);
                 * }*/
            }
        }
    }
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _myConsumer        = new MyConsumer(GetTask <A>());
            _transactionFilter = new TransactionFilter(GetTask <bool>(), GetTask <bool>());

            configurator.Consumer(() => _myConsumer, x => x.UseFilter(_transactionFilter));
        }
示例#4
0
        public void ManuallyComposedTypeWithMultipleTranslatorsHandlesMessageProperly()
        {
            var message3 = new Message3 {
                CorrelationId = "1234"
            };

            var      bus              = new Bus();
            Message4 message4         = null;
            var      message2Consumer = new MyConsumer();

            bus.AddHandler(message2Consumer);
            bus.AddHandler(new ActionConsumer <Message4>(m => message4 = m));
            var pipe = new Pipe();

            bus.AddTranslator(pipe);
            bus.AddTranslator(new ActionPipe <Message3, Message4>(m => new Message4 {
                CorrelationId = m.CorrelationId
            }));

            bus.Handle(message3);

            Assert.IsNotNull(message4);
            Assert.AreEqual(message3.CorrelationId, message4.CorrelationId);
            Assert.IsNotNull(Pipe.LastMessageProcessed);
            Assert.AreEqual(message3.CorrelationId, message4.CorrelationId);
        }
示例#5
0
        public void Should_be_able_to_call_the_consumer_directly()
        {
            var consumer = new MyConsumer(new SynchronousFiber());

            consumer.CommandChannel.Send(new MyCommand());

            consumer.Called.IsCompleted.ShouldBeTrue();
        }
示例#6
0
        public void Invoking_generic_method()
        {
            var consumer = new MyConsumer();

            consumer.GetType().InvokeMember("Consume", BindingFlags.InvokeMethod, null, consumer, new[] { new MyMessage() });

            Assert.IsTrue(consumer.Consumed);
        }
示例#7
0
        public void Should_be_able_to_call_the_consumer_directly()
        {
            var consumer = new MyConsumer(new SynchronousFiber());

            consumer.CommandChannel.Send(new MyCommand());

            consumer.Called.IsCompleted.ShouldBeTrue();
        }
示例#8
0
        public void Invoking_generic_method()
        {
            var consumer = new MyConsumer();

            consumer.GetType().InvokeMember("Consume", BindingFlags.InvokeMethod, null, consumer, new[]{new MyMessage()});

            Assert.IsTrue(consumer.Consumed);
        }
示例#9
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _consumer = new MyConsumer(GetTask <ConsumeContext <PingMessage> >());

            configurator.Consumer(() => _consumer, x =>
            {
                x.ConfigureMessage <PingMessage>(m => m.UseScheduledRedelivery(Retry.Intervals(1000, 2000)));
            });
        }
示例#10
0
        public static int Main(string[] args)
        {
            if (args.Length < 4)
            {
                Console.Error.WriteLine("Usage: LowlevelLogTail <uri> <exchange> <exchangetype> <routingkey>");
                Console.Error.WriteLine("RabbitMQ .NET client version " + typeof(IModel).Assembly.GetName().Version.ToString());
                Console.Error.WriteLine("Parameters:");
                Console.Error.WriteLine("  <uri> = \"amqp://*****:*****@host:port/vhost\"");
                Console.Error.WriteLine("If the exchange name is the empty string, will instead declare a queue named");
                Console.Error.WriteLine("by the routingkey, and consume from that queue.");
                return(2);
            }

            string serverAddress = args[0];
            string exchange      = args[1];
            string exchangeType  = args[2];
            string routingKey    = args[3];

            ConnectionFactory cf = new ConnectionFactory();

            cf.Uri = serverAddress;
            using (IConnection conn = cf.CreateConnection())
            {
                using (IModel ch = conn.CreateModel())
                {
                    string queueName;
                    if (exchange == "")
                    {
                        ch.QueueDeclare(routingKey, false, true, true, null);
                        queueName = routingKey;
                    }
                    else
                    {
                        ch.ExchangeDeclare(exchange, exchangeType);
                        queueName = ch.QueueDeclare();
                        ch.QueueBind(queueName, exchange, routingKey, null);
                    }

                    MyConsumer consumer = new MyConsumer(ch);
                    ch.BasicConsume(queueName, false, consumer);

                    Console.WriteLine("Consumer tag: " + consumer.ConsumerTag);

                    while (consumer.IsRunning)
                    {
                        // Dummy main thread. Often, this will be
                        // a GUI thread or similar.
                        Thread.Sleep(500);
                    }

                    return(0);
                }
            }
        }
示例#11
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            base.ConfigureInMemoryReceiveEndpoint(configurator);

            _consumer = new MyConsumer();

            configurator.Consumer(() => _consumer, x =>
            {
                x.Message <TestMessage>(v => v.UseContextFilter(async context => context.Message.Key == "ACCEPT"));
            });

            _accepted = Handled <TestMessage>(configurator, x => x.Message.Key == "ACCEPT");
            _denied   = Handled <TestMessage>(configurator, x => x.Message.Key == "DENY");
        }
示例#12
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _consumer = new MyConsumer(GetTask <PingMessage>());

            _message         = GetTask <PingMessage>();
            _consumerOnly    = GetTask <MyConsumer>();
            _consumerMessage = GetTask <Tuple <MyConsumer, PingMessage> >();

            configurator.Instance(_consumer, cfg =>
            {
                cfg.UseExecute(context => _consumerOnly.TrySetResult(context.Consumer));
                cfg.Message <PingMessage>(m => m.UseExecute(context => _message.TrySetResult(context.Message)));
                cfg.ConsumerMessage <PingMessage>(m => m.UseExecute(context => _consumerMessage.TrySetResult(Tuple.Create(context.Consumer, context.Message))));
            });
        }
示例#13
0
    static void Main(string[] args)
    {
        BoundedBuffer boundedBuffer = new BoundedBuffer();

        MyProducer prod           = new MyProducer(boundedBuffer, 20);
        Thread     producerThread = prod.CreateProducerThread();

        MyConsumer cons           = new MyConsumer(boundedBuffer, 20);
        Thread     consumerThread = cons.CreateConsumerThread();

        producerThread.Start();
        consumerThread.Start();

        Console.ReadLine();
    }
        public static int Main(string[] args) {
            if (args.Length < 4) {
                Console.Error.WriteLine("Usage: LowlevelLogTail <uri> <exchange> <exchangetype> <routingkey>");
                Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
                Console.Error.WriteLine("Parameters:");
                Console.Error.WriteLine("  <uri> = \"amqp://*****:*****@host:port/vhost\"");
                Console.Error.WriteLine("If the exchange name is the empty string, will instead declare a queue named");
                Console.Error.WriteLine("by the routingkey, and consume from that queue.");
                return 2;
            }

            string serverAddress = args[0];
            string exchange = args[1];
            string exchangeType = args[2];
            string routingKey = args[3];

            ConnectionFactory cf = new ConnectionFactory();
            cf.Uri = serverAddress;
            using (IConnection conn = cf.CreateConnection())
                {
                    using (IModel ch = conn.CreateModel())
                        {
                            string queueName;
                            if (exchange == "") {
                                ch.QueueDeclare(routingKey, false, true, true, null);
                                queueName = routingKey;
                            } else {
                                ch.ExchangeDeclare(exchange, exchangeType);
                                queueName = ch.QueueDeclare();
                                ch.QueueBind(queueName, exchange, routingKey, null);
                            }

                            MyConsumer consumer = new MyConsumer(ch);
                            ch.BasicConsume(queueName, false, consumer);

                            Console.WriteLine("Consumer tag: " + consumer.ConsumerTag);

                            while (consumer.IsRunning) {
                                // Dummy main thread. Often, this will be
                                // a GUI thread or similar.
                                Thread.Sleep(500);
                            }

                            return 0;
                        }
                }
        }
示例#15
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _consumer = new MyConsumer(GetTask <Message>());

            configurator.Instance(_consumer);
        }