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


C# IModel.BasicConsume方法代码示例

本文整理汇总了C#中IModel.BasicConsume方法的典型用法代码示例。如果您正苦于以下问题:C# IModel.BasicConsume方法的具体用法?C# IModel.BasicConsume怎么用?C# IModel.BasicConsume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IModel的用法示例。


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

示例1: ReceiveDotNetObjects

        private static void ReceiveDotNetObjects(IModel model)
        {
            model.BasicQos(0, 1, false);
            QueueingBasicConsumer consumer = new QueueingBasicConsumer(model);
            model.BasicConsume(CommonService.DotNetObjectQueueName, false, consumer);
            while (true)
            {

                BasicDeliverEventArgs deliveryArguments = consumer.Queue.Dequeue() as BasicDeliverEventArgs;
                string objectType = deliveryArguments.BasicProperties.Type;
                Type t = Type.GetType(objectType);
                String jsonified = Encoding.UTF8.GetString(deliveryArguments.Body);
                object rawObject = JsonConvert.DeserializeObject(jsonified, t);
                Console.WriteLine("Object type: {0}", objectType);

                if (rawObject.GetType() == typeof(Customer))
                {
                    Customer customer = rawObject as Customer;
                    Console.WriteLine("Customer name: {0}", customer.Name);
                }
                else if (rawObject.GetType() == typeof(NewCustomer))
                {
                    NewCustomer newCustomer = rawObject as NewCustomer;
                    Console.WriteLine("NewCustomer name: {0}", newCustomer.Name);
                }
                model.BasicAck(deliveryArguments.DeliveryTag, false);
            }
        }
开发者ID:JamisonWhite,项目名称:rabbitmqdotnet,代码行数:28,代码来源:Program.cs

示例2: 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

示例3: Start

        public void Start()
        {
            try
            {
                IsReceiving = true;

                _channel = GetNewChannel();
                _channelId = Guid.NewGuid();

                var consumer = new QueueingBasicConsumer(_channel);

                _channel.BasicConsume(Properties.QueueName, false, consumer);

                _continueReceiving = ContinueReceiving;

                Logger.Debug("��ʼ������Ϣ��ͨ��Id[{0}]", _channelId);

                _asyncResult = _continueReceiving.BeginInvoke(consumer, _channelId, _channel, null, null);
            }
            catch(Exception ex)
            {
                Logger.Error(ex);
                throw new MqException("�����Ϣ���м���ʧ�ܡ�", ex);
            }
        }
开发者ID:IcyExile,项目名称:CRQ,代码行数:25,代码来源:MessageReceiver.cs

示例4: 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

示例5: 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

示例6: 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

示例7: RabbitMqEventConsumer

        /// <summary>
        /// Initializes a new instance of the <see cref="RabbitMqEventConsumer"/> class.
        /// </summary>
        /// <param name="connectionFactory">The connection factory.</param>
        /// <param name="exchangePath">The exchange path.</param>
        /// <param name="queue">The queue.</param>
        public RabbitMqEventConsumer(ConnectionFactory connectionFactory, string exchangePath, string queue)
        {
            _active = 1;
            _connection = connectionFactory.CreateConnection();
            _model = _connection.CreateModel();
            _queue = _model.QueueDeclare(queue, true, false, false, new Hashtable());

            // bind the queue to an exchange if specified
            if (exchangePath != null)
            {
                _model.QueueBind(_queue, exchangePath, string.Empty);
            }

            EventingBasicConsumer eventingBasicConsumer = new EventingBasicConsumer();
            eventingBasicConsumer.Received += HandleEvent;

            _model.BasicConsume(_queue, true, eventingBasicConsumer);

            #if false
            _subscription = new Subscription(_model, _queue, true);
            var thread = new Thread(ReceiveEvents);
            thread.IsBackground = true;
            thread.Name = "rabbitmq:consumer";
            thread.Start();
            #endif

            var uriBuilder = new UriBuilder(
                "rabbitmq",
                connectionFactory.HostName,
                connectionFactory.Port,
                queue);

            Uri = uriBuilder.Uri;
        }
开发者ID:RussPAll,项目名称:nesper-catalyst,代码行数:40,代码来源:RabbitMqEventConsumer.cs

示例8: 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

示例9: MessageQueue

        //private string _exchange;
        //_________________________________________________________________________________________________
        // Constructor, it initializes the message queue to just consume messages
        public MessageQueue(string server, string exchange, string queue)
        {
            try
            {
                ConnectionFactory factory;

                /*server = (server == null) ? ConfigurationManager.AppSettings["queueServer"] : server;
                _queueName = (queue == null) ? ConfigurationManager.AppSettings["queueName"] : queue;*/
                _queueName = queue;

                factory = new ConnectionFactory();
                factory.UserName = "guest";
                factory.Password = "guest";
                factory.Port = 5672; // default is 5672
                factory.VirtualHost = "/"; // default is "/"
                factory.HostName = server;

                _conn = factory.CreateConnection();
                _channel = _conn.CreateModel();

                _channel.QueueDeclare(_queueName, true, false, false, null); // it will save to the disk

                _channel.BasicQos(0, 1, false); // get just 1 message

                // We configure the class to have a event consumer
                _consumer = new QueueingBasicConsumer(_channel);
                _channel.BasicConsume(_queueName, false, _consumer);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
开发者ID:B3RTG,项目名称:IMSTemplates,代码行数:36,代码来源:MessageQueue.cs

示例10: RPCClient

 public RPCClient()
 {
     var factory = new ConnectionFactory() { HostName = "localhost" };
     connection = factory.CreateConnection();
     channel = connection.CreateModel();
     replyQueueName = channel.QueueDeclare();
     consumer = new QueueingBasicConsumer(channel);
     channel.BasicConsume(replyQueueName, true, consumer);
 }
开发者ID:harlan1,项目名称:rabbitmq-tutorials,代码行数:9,代码来源:RPCClient.cs

示例11: Connect

        public void Connect()
        {
            _connectionFactory = new ConnectionFactory() { HostName = "localhost" };
            _connection = _connectionFactory.CreateConnection();
            _channel = _connection.CreateModel();
            _channel.QueueDeclare("hello", false, false, false, null);

            _consumer = new QueueingBasicConsumer(_channel);
            _channel.BasicConsume("hello", true, _consumer);
        }
开发者ID:dangordon,项目名称:RabbitMQTest,代码行数:10,代码来源:Rabbit.cs

示例12: CreateConnection

        public void CreateConnection()
        {
            var factory = new ConnectionFactory { HostName = "localhost", UserName = "guest", Password = "guest" };
            _connection = factory.CreateConnection();
            _channel = _connection.CreateModel();

            _replyQueueName = _channel.QueueDeclare("rpc_reply", true, false, false, null);           

            _consumer = new QueueingBasicConsumer(_channel);
            _channel.BasicConsume(_replyQueueName, true, _consumer);
        }
开发者ID:FantasticFiasco,项目名称:sandbox,代码行数:11,代码来源:RabbitMQDirectClient.cs

示例13: RpcQueue

 public RpcQueue()
 {
     var factory = new ConnectionFactory() {HostName = "diablo" , UserName = "guest", Password = "guest" };
     connection = factory.CreateConnection();
     channel = connection.CreateModel();
     replyQueueName = channel.QueueDeclare().QueueName;
     consumer = new QueueingBasicConsumer(channel);
     channel.BasicConsume(queue: replyQueueName,
                          noAck: true,
                          consumer: consumer);
 }
开发者ID:wgaalves,项目名称:RabbitMQ-Unity,代码行数:11,代码来源:RpcQueue.cs

示例14: CreateConnection

 public void CreateConnection()
 {
     _factory = new ConnectionFactory { HostName = "localhost", UserName = "guest", Password = "guest" };
     _connection = _factory.CreateConnection();
     _channel = _connection.CreateModel();
     _channel.QueueDeclare("rpc_queue", false, false, false, null);
     _channel.BasicQos(0, 1, false);
     _consumer = new QueueingBasicConsumer(_channel);
     _channel.BasicConsume("rpc_queue", false, _consumer);
     _rnd = new Random();
 }
开发者ID:FantasticFiasco,项目名称:sandbox,代码行数:11,代码来源:RabbitMQConsumer.cs

示例15: RpcClient

        public RpcClient(ConnectionFactory connectionFactory, string queue)
        {
            amqpConnectionFactory = connectionFactory;
            queueName = queue;

            connection = amqpConnectionFactory.CreateConnection();
            channel = connection.CreateModel();
            replyQueueName = channel.QueueDeclare();
            consumer = new QueueingBasicConsumer(channel);
            channel.BasicConsume(replyQueueName, true, consumer);
        }
开发者ID:stefanprodan,项目名称:EsnServiceBus,代码行数:11,代码来源:RpcClient.cs


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