当前位置: 首页>>代码示例>>C#>>正文


C# Events.EventingBasicConsumer类代码示例

本文整理汇总了C#中RabbitMQ.Client.Events.EventingBasicConsumer的典型用法代码示例。如果您正苦于以下问题:C# EventingBasicConsumer类的具体用法?C# EventingBasicConsumer怎么用?C# EventingBasicConsumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EventingBasicConsumer类属于RabbitMQ.Client.Events命名空间,在下文中一共展示了EventingBasicConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartListening

        public override void StartListening()
        {
            _rabbitConnection = Configuration.ConnectionFactory.CreateConnection();

            _publishModel = _rabbitConnection.CreateModel();
            _subscribeModel = _rabbitConnection.CreateModel();

            _publishModel.ExchangeDeclare(Configuration.StampExchangeName, "x-stamp", durable: true);
            _subscribeModel.ExchangeDeclare(Configuration.ExchangeName, ExchangeType.Fanout, durable: true);
            _subscribeModel.QueueDeclare(Configuration.QueueName, durable: false, exclusive: false, autoDelete: true, arguments: new Dictionary<string, object>());
            _subscribeModel.QueueBind(Configuration.QueueName, Configuration.ExchangeName, "");

            var consumer = new EventingBasicConsumer(_subscribeModel);
            consumer.Received += (sender, args) =>
            {
                try
                {
                    OnMessage(new RabbitMqMessageWrapper
                    {
                        Bytes = args.Body,
                        Id = Convert.ToUInt64(args.BasicProperties.Headers["stamp"])
                    });
                }
                finally
                {
                    _subscribeModel.BasicAck(args.DeliveryTag, multiple: false);
                }
            };

            _subscribeModel.BasicConsume(Configuration.QueueName, noAck: false, consumer: consumer);
        }
开发者ID:mdevilliers,项目名称:SignalR.RabbitMq,代码行数:31,代码来源:RabbitConnection.cs

示例2: RabbitMqConsumer

        public RabbitMqConsumer(Uri uri, string exchange, IEnumerable<string> routingKeys)
        {
            var connectionFactory = new ConnectionFactory
                {
                    Uri = uri.ToString(),
                };
            _connection = connectionFactory.CreateConnection();
            _model = _connection.CreateModel();

            _model.ExchangeDeclare(exchange, ExchangeType.Topic, false);

            var queueName = string.Format("test-{0}", Guid.NewGuid());
            _model.QueueDeclare(
                queueName,
                false,
                false,
                true,
                null);

            foreach (var routingKey in routingKeys)
            {
                _model.QueueBind(
                    queueName,
                    exchange,
                    routingKey,
                    null);
            }

            _eventingBasicConsumer = new EventingBasicConsumer(_model);
            _eventingBasicConsumer.Received += OnReceived;

            _model.BasicConsume(queueName, false, _eventingBasicConsumer);
        }
开发者ID:joaomajesus,项目名称:EventFlow,代码行数:33,代码来源:RabbitMqConsumer.cs

示例3: Consumer

        public Consumer(string queueName, IDictionary<string, string> headers, bool matchAll = true)
        {
            var factory = new ConnectionFactory {HostName = "localhost"};
            _connection = factory.CreateConnection();
            _channel = _connection.CreateModel();

            var args = new Dictionary<String, Object>();
            if (headers != null)
            {
                args.Add("x-match", matchAll ? "all" : "any");

                foreach (var item in headers)
                {
                    args.Add(item.Key, item.Value);
                }
            }

            _channel.ExchangeDeclare(ExchangeName, "headers", true);
            _channel.QueueDeclare(queueName, true, false, false, args);
            _channel.QueueBind(queueName, ExchangeName, string.Empty);

            const bool nonTransactional = true;
            _consumer = new EventingBasicConsumer();
            _consumer.Received += ConsumerReceived;
            _channel.BasicConsume(queueName, nonTransactional, _consumer);
        }
开发者ID:toddmeinershagen,项目名称:Demo.RabbitMQ,代码行数:26,代码来源:Consumer.cs

示例4: Main

        private static void Main(string[] args)
        {
            Console.WriteLine("----------Sad Receiver----------");
            Console.WriteLine("Press [Enter] to exit.");

            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(exchange: "Emotional_Messages",
                    type: "direct");
                var queueName = channel.QueueDeclare().QueueName;


                channel.QueueBind(queue: queueName,
                    exchange: "Emotional_Messages",
                    routingKey: "Sad");

                Console.WriteLine("Waiting for messages...");

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" Received {0}", message);
                };
                channel.BasicConsume(queue: queueName,
                    noAck: true,
                    consumer: consumer);

                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
            }
        }
开发者ID:tgkuzma,项目名称:RabbitMq-Routing,代码行数:35,代码来源:Program.cs

示例5: Main

    public static void Main()
    {
        var factory = new ConnectionFactory() { HostName = "localhost" };
        using(var connection = factory.CreateConnection())
        using(var channel = connection.CreateModel())
        {
            channel.QueueDeclare(queue: "task_queue", durable: true, exclusive: false, autoDelete: false, arguments: null);

            channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);

            Console.WriteLine(" [*] Waiting for messages.");

            var consumer = new EventingBasicConsumer(channel);
            consumer.Received += (model, ea) =>
            {
                var body = ea.Body;
                var message = Encoding.UTF8.GetString(body);
                Console.WriteLine(" [x] Received {0}", message);

                int dots = message.Split('.').Length - 1;
                Thread.Sleep(dots * 1000);

                Console.WriteLine(" [x] Done");

                channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
            };
            channel.BasicConsume(queue: "task_queue", noAck: false, consumer: consumer);

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
    }
开发者ID:Fortiz2305,项目名称:rabbitmq-tutorials,代码行数:32,代码来源:Worker.cs

示例6: HandleQueueItems

        public static void HandleQueueItems()
        {
            var factory = new ConnectionFactory { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "VehicleQueue",
                                     durable: false,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" [x] Received {0}", message);
                    PluginManager.HandleMessageForLoadedPlugins(new ExampleMessage { BodyText = message });
                };
                channel.BasicConsume(queue: "VehicleQueue",
                                     noAck: true,
                                     consumer: consumer);
                Thread.Sleep(new TimeSpan(0, 0, 10));
            }
        }
开发者ID:HudsonAkridge,项目名称:MQCoordinator,代码行数:26,代码来源:RabbitMQProcessor.cs

示例7: Connect

        private void Connect()
        {
            var cf = new ConnectionFactory();
            _connection = cf.CreateConnection();
            _channel = _connection.CreateModel();
            _channel.ExchangeDeclare(_configurationService.WorkersExchange, ExchangeType.Direct);

            // Listen for heartbeats
            _channel.QueueDeclare(_configurationService.WorkerPingQueue, false, false, true, null);
            _channel.QueueBind(_configurationService.WorkerPingQueue, _configurationService.WorkersExchange, _configurationService.WorkerPingQueue);
            var heartbeatConsumer = new EventingBasicConsumer(_channel);
            heartbeatConsumer.Received += OnReceivedHeartbeat;
            heartbeatConsumer.ConsumerCancelled += OnConsumerCancelled;
            heartbeatConsumer.Shutdown += OnShutdown;
            _channel.BasicConsume(_configurationService.WorkerPingQueue, true, heartbeatConsumer);

            // Listen or status changes
            _channel.QueueDeclare(_configurationService.WorkerStatusQueue, false, false, true, null);
            _channel.QueueBind(_configurationService.WorkerStatusQueue, _configurationService.WorkersExchange, _configurationService.WorkerStatusQueue);
            var statusConsumer = new EventingBasicConsumer(_channel);
            statusConsumer.Received += OnReceivedStatus;
            statusConsumer.ConsumerCancelled += OnConsumerCancelled;
            statusConsumer.Shutdown += OnShutdown;
            _channel.BasicConsume(_configurationService.WorkerStatusQueue, false, statusConsumer);
        }
开发者ID:bpe78,项目名称:DistributedResourceManager_RabbitMq,代码行数:25,代码来源:WorkerNodeManagerActor.cs

示例8: Main

        private static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { Uri = "amqp://nopqbtng:[email protected]/nopqbtng" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(exchange: "OnAMission", type: "fanout");

                var queueName = channel.QueueDeclare().QueueName;
                channel.QueueBind(queue: queueName,
                                  exchange: "OnAMission",
                                  routingKey: "");

                Console.WriteLine(" [*] Waiting for logs.");

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" [x] {0}", message);
                };
                channel.BasicConsume(queue: queueName,
                                     noAck: true,
                                     consumer: consumer);

                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
            }
        }
开发者ID:rosalindwills,项目名称:RabbitMQDemo,代码行数:30,代码来源:Program.cs

示例9: Main

        private static void Main(string[] args)
        {
            Console.WriteLine("----------Receiver (ALL HAPPY MESSAGES)----------");
            Console.WriteLine("Press [Enter] to exit.");

            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(exchange: "topic_example", type: "topic");
                var queueName = channel.QueueDeclare().QueueName;

                channel.QueueBind(queue: queueName,
                                  exchange: "topic_example",
                                  routingKey: "Happy.*");

                Console.WriteLine("Waiting for messages...");

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    var routingKey = ea.RoutingKey;
                    Console.WriteLine(" Received '{0}':'{1}'",
                                      routingKey,
                                      message);
                };
                channel.BasicConsume(queue: queueName,
                                     noAck: true,
                                     consumer: consumer);

                Console.ReadLine();
            }
        }
开发者ID:tgkuzma,项目名称:RabbitMq-Topic,代码行数:35,代码来源:Program.cs

示例10: Main

        static void Main(string[] args)
        {
            var factory = GetConnectionFactory();
              using (var connection = factory.CreateConnection())
              {
            using (var channel = connection.CreateModel())
            {
              DeclareExchange(channel);
              DeclareQ(channel, Constants.MASTER_CUSTOMER_QUEUE_NAME);
              SetUpQoS(channel);

              BindToQ(channel, Constants.MASTER_CUSTOMER_QUEUE_NAME, Constants.NEW_CUSTOMER_EVENT);

              Console.WriteLine(" [CRM] Waiting for messages.");

              var consumer = new EventingBasicConsumer(channel);
              consumer.Received += (Model, ea) =>
              {
            var body = ea.Body;
            var message = Encoding.UTF8.GetString(body);
            var routingKey = ea.RoutingKey;

            Console.WriteLine(" [>>>>>>>>>>] Received MESSAGE '{0}'", routingKey);

            ProcessMessage(channel, message, routingKey);
            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
              };
              channel.BasicConsume(queue: Constants.MASTER_CUSTOMER_QUEUE_NAME, noAck: false, consumer: consumer);

              Console.WriteLine(" Press [enter] to exit.");
              Console.ReadLine();
            }
              }
        }
开发者ID:shawnewallace,项目名称:choreographed_process,代码行数:34,代码来源:Program.cs

示例11: Rabbit

        public Rabbit(string address)
        {
            cf = new ConnectionFactory();
            //cf.Port = 35672;
            cf.UserName = "eventHub";
            cf.Password = "18daigaku75";
            cf.Address = address;
            conn = cf.CreateConnection();
            IModel c = Connect();
            conn.AutoClose = false;
            UriSettings();

            _address = address.Substring(0, address.IndexOf(":"));

            ProcessQueues();

            System.Timers.Timer aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Interval = 60 * 1000;
            aTimer.Enabled = true;

            var consumer = new EventingBasicConsumer();
            consumer.Received += (model, ea) =>
            {
                ProcessQueues();
                Console.WriteLine("Received event");
            };

            c.BasicConsume("task_queue", false, null, consumer);

            Console.ReadKey();
        }
开发者ID:byu-oit-appdev,项目名称:EventDispatcher,代码行数:32,代码来源:Rabbit.cs

示例12: StartListening

        public override void StartListening()
        {
            _rabbitConnection = _configuration.RabbitMqClusterMembers?.Count > 0
                ? _configuration.ConnectionFactory.CreateConnection(_configuration.RabbitMqClusterMembers)
                : _configuration.ConnectionFactory.CreateConnection();
            _publishModel = _rabbitConnection.CreateModel();
            _receiveModel = _rabbitConnection.CreateModel();
            _receiveModel.ExchangeDeclare(_configuration.ExchangeName, ExchangeType.Fanout, true);
            var queue = _configuration.QueueName == null
                ? _receiveModel.QueueDeclare()
                : _receiveModel.QueueDeclare(_configuration.QueueName, true, false, false,
                    new Dictionary<string, object>());
            _receiveModel.QueueBind(queue.QueueName, _configuration.ExchangeName, "");

            var consumer = new EventingBasicConsumer(_receiveModel);
            consumer.Received += (sender, args) =>
            {
                var message = new RabbitMqMessageWrapper
                {
                    Bytes = args.Body,
                    Id =
                        Convert.ToUInt64(Encoding.UTF8.GetString((byte[]) args.BasicProperties.Headers[MessageIdHeader]))
                };
                OnMessage(message);
            };

            _receiveModel.BasicConsume(queue.QueueName, true, consumer);
        }
开发者ID:chrisdrobison,项目名称:SignalR.MongoRabbit,代码行数:28,代码来源:MongoRabbitConnection.cs

示例13: TestEventingConsumerRegistrationEvents

        public void TestEventingConsumerRegistrationEvents()
        {
            string q = Model.QueueDeclare();

            var registeredLatch = new ManualResetEvent(false);
            object registeredSender = null;
            var unregisteredLatch = new ManualResetEvent(false);
            object unregisteredSender = null;

            EventingBasicConsumer ec = new EventingBasicConsumer(Model);
            ec.Registered += (s, args) =>
            {
                registeredSender = s;
                registeredLatch.Set();
            };

            ec.Unregistered += (s, args) =>
            {
                unregisteredSender = s;
                unregisteredLatch.Set();
            };

            string tag = Model.BasicConsume(q, false, ec);
            Wait(registeredLatch);

            Assert.IsNotNull(registeredSender);
            Assert.AreEqual(ec, registeredSender);
            Assert.AreEqual(Model, ((EventingBasicConsumer)registeredSender).Model);

            Model.BasicCancel(tag);
            Wait(unregisteredLatch);
            Assert.IsNotNull(unregisteredSender);
            Assert.AreEqual(ec, unregisteredSender);
            Assert.AreEqual(Model, ((EventingBasicConsumer)unregisteredSender).Model);
        }
开发者ID:hanxinimm,项目名称:rabbitmq-dotnet-client,代码行数:35,代码来源:TestEventingConsumer.cs

示例14: Main

        public static void Main()
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {// tutaj tez deklarujemy kolejke, ze wzgledu na to, iż możemy rozpoczac odbnieranie nim wysłannik wyśle wiadomość
                //chcemy miec pewnośc, że kolejka istnieje 
                channel.QueueDeclare(queue: "hello",
                                     durable: false,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);
                //mowimy serwerowi by dostarczył nam wiadomośc z kolejki

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                    {
                        var body = ea.Body;
                        var message = Encoding.UTF8.GetString(body);
                        Console.WriteLine(" [x] Received {0}", message);
                    };
                channel.BasicConsume(queue: "hello",
                                     noAck: true,
                                     consumer: consumer);

                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
            }
        }
开发者ID:PowerAmbroz,项目名称:RabbitMQ,代码行数:29,代码来源:Receive.cs

示例15: Subscribe

 public void Subscribe(string queueName, EventHandler<BasicDeliverEventArgs> handler)
 {
     CreateQueue(queueName);
     var consumer = new EventingBasicConsumer(_model);
     consumer.Received += handler;
     _model.BasicConsume(queueName, true, consumer);
 }
开发者ID:tgkuzma,项目名称:RabbitMq-Finance,代码行数:7,代码来源:MessagingManager.cs


注:本文中的RabbitMQ.Client.Events.EventingBasicConsumer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。