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


C# IModel.QueueBind方法代码示例

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


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

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

示例2: DeclareExchangeAndQueues

        //NOTE This is the only method that cannot be moved into RestBus.Common so keep that in mind if intergrating other Amqp brokers
        public static void DeclareExchangeAndQueues(IModel channel, ExchangeInfo exchangeInfo, object syncObject, string subscriberId )
        {
            //TODO: IS the lock statement here necessary?
            lock (syncObject)
            {
                string exchangeName = AmqpUtils.GetExchangeName(exchangeInfo);
                string workQueueName = AmqpUtils.GetWorkQueueName(exchangeInfo);

                if (exchangeInfo.Exchange != "")
                {
                    //TODO: If Queues are durable then exchange ought to be too.
                    channel.ExchangeDeclare(exchangeName, exchangeInfo.ExchangeType, false, true, null);
                }

                var workQueueArgs = new Dictionary<string, object>();
                workQueueArgs.Add("x-expires", (long)AmqpUtils.GetWorkQueueExpiry().TotalMilliseconds);

                //TODO: the line below can throw some kind of socket exception, so what do you do in that situation
                //Bear in mind that Restart may call this code.
                //The exception name is the OperationInterruptedException

                //Declare work queue
                channel.QueueDeclare(workQueueName, false, false, false, workQueueArgs);
                channel.QueueBind(workQueueName, exchangeName, AmqpUtils.GetWorkQueueRoutingKey());

                if(subscriberId != null)
                {
                    string subscriberQueueName = AmqpUtils.GetSubscriberQueueName(exchangeInfo, subscriberId);

                    var subscriberQueueArgs = new Dictionary<string, object>();
                    subscriberQueueArgs.Add("x-expires", (long)AmqpUtils.GetSubscriberQueueExpiry().TotalMilliseconds);

                    //TODO: Look into making the subscriber queue exclusive
                    //and retry with a different id if the queue has alreasy been taken.
                    //in this case the Id property of the ISubscriber interface should be changed to GetId()
                    //and will be documented to return the "current" id.
                    //In fact Hide GetId and id property for both client and subscriber, they should be private for now.
                    //Write something similar for the client.

                    //TODO: the line below can throw some kind of socket exception, so what do you do in that situation
                    //Bear in mind that Restart may call this code.
                    //The exception name is the OperationInterruptedException

                    //Declare subscriber queue
                    channel.QueueDeclare(subscriberQueueName, false, false, true, subscriberQueueArgs);
                    channel.QueueBind(subscriberQueueName, exchangeName, subscriberId);
                }

            }
        }
开发者ID:david-x-chen,项目名称:RestBus,代码行数:51,代码来源:AmqpUtils.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: BaseConsumer

        protected BaseConsumer(string hostName, string exchangeName, string user, string pass, params string[] bindingKeys)
        {
            this.exchangeName = exchangeName;
            this.hostName = hostName;

            var connectionFactory = new ConnectionFactory()
            {
                HostName = hostName,
                UserName = user,
                Password = pass
            };

            connection = connectionFactory.CreateConnection();
            model = connection.CreateModel();
            //model.BasicQos(0, 1, false);

            model.ExchangeDeclare(exchangeName, "topic");

            queue = DeclareQueue(Queue);

            foreach (var key in bindingKeys)
            {
                model.QueueBind(queue, exchangeName, key);
            }
        }
开发者ID:aesamson,项目名称:RabbitMQ,代码行数:25,代码来源:BaseConsumer.cs

示例5: EstablishConnection

        private void EstablishConnection()
        {
            try
            {
                if (connection != null)
                {
                    if (connection.IsOpen)
                        return;
                    throw new CannotConnectException(string.Format("Cannot connect to {0}", configuration.ConnectionUri));
                }

                var connectionFactory = new ConnectionFactory
                    {
                        Uri = configuration.ConnectionUri,
                        AutomaticRecoveryEnabled = true,
                        TopologyRecoveryEnabled = true,
                        UseBackgroundThreadsForIO = true,
                        RequestedHeartbeat = 10,
                    };
                connection = connectionFactory.CreateConnection();
                channel = connection.CreateModel();
                channel.ExchangeDeclare(configuration.Exchange, configuration.ExchangeType, true);
                channel.QueueDeclare(configuration.Queue, true, false, false, new Dictionary<string, object>());
                channel.QueueBind(configuration.Queue, configuration.Exchange, configuration.RoutingKey);
            }
            catch (Exception exception)
            {
                channel.SafeDispose();
                channel = null;
                connection.SafeDispose();
                connection = null;
                throw new CannotConnectException(string.Format("Cannot connect to {0}", configuration.ConnectionUri), exception);
            }
        }
开发者ID:palpha,项目名称:EasyGelf,代码行数:34,代码来源:AmqpTransport.cs

示例6: SetupInitialTopicQueue

        private static void SetupInitialTopicQueue(IModel model)
        {
            model.QueueDeclare("queueFromVisualStudio", true, false, false, null);

            model.ExchangeDeclare("exchangeFromVisualStudio", ExchangeType.Topic, true);
            model.QueueBind("queueFromVisualStudio", "exchangeFromVisualStudio", "superstars");
        }
开发者ID:JamisonWhite,项目名称:rabbitmqdotnet,代码行数:7,代码来源:Program.cs

示例7: BindQueue

 protected void BindQueue(QueueConfiguration queue, ExchangeConfiguration exchange, string routingKey, IModel channel = null)
 {
     if (exchange.IsDefaultExchange())
     {
         /*
             "The default exchange is implicitly bound to every queue,
             with a routing key equal to the queue name. It it not possible
             to explicitly bind to, or unbind from the default exchange."
         */
         return;
     }
     if (queue.IsDirectReplyTo())
     {
         /*
             "Consume from the pseudo-queue amq.rabbitmq.reply-to in no-ack mode. There is no need to
             declare this "queue" first, although the client can do so if it wants."
             - https://www.rabbitmq.com/direct-reply-to.html
         */
         return;
     }
     _logger.LogDebug($"Binding queue {queue.QueueName} to exchange {exchange.ExchangeName} with routing key {routingKey}");
     channel = channel ?? ChannelFactory.GetChannel();
     channel
         .QueueBind(
             queue: queue.FullQueueName,
             exchange: exchange.ExchangeName,
             routingKey: routingKey
         );
 }
开发者ID:Originalutter,项目名称:RawRabbit,代码行数:29,代码来源:OperatorBase.cs

示例8: RabbitMQPublisher

        public RabbitMQPublisher(string connection)
        {
            factory = new ConnectionFactory();

            if (connection != null && connection != string.Empty)
            {
                factory.Uri = connection;
            }
            else
            {
                factory.HostName = "localhost";
            }

            Console.WriteLine("Creating connection...");
            factory.Protocol = Protocols.FromEnvironment();

            conn = factory.CreateConnection();

            Console.WriteLine("Creating channel...");
            model = conn.CreateModel();

            Console.WriteLine("Creating exchange...");
            model.ExchangeDeclare("exch", ExchangeType.Direct);

            Console.WriteLine("Creating queue...");
            model.QueueDeclare("queue", true, false, true, null);

            model.QueueBind("queue", "exch", "key", new Dictionary<string, object>());
        }
开发者ID:ryzam,项目名称:Vaccine-CQRS,代码行数:29,代码来源:RabbitMQPublisher.cs

示例9: Connect

        public IModel Connect(AmqpSettings settings)
        {
            var factory = new ConnectionFactory
            {
                UserName = settings.user
                ,
                Password = settings.password
                ,
                HostName = settings.hostName
                ,
                AutomaticRecoveryEnabled = true
                ,
                NetworkRecoveryInterval = TimeSpan.FromSeconds(10);
            };

            _connect = factory.CreateConnection();

            _channel = _connect.CreateModel();

            _channel.ExchangeDeclare(settings.exchangeName, ExchangeType.Direct);
            _channel.QueueDeclare(settings.queueName, false, false, false, null);
            _channel.QueueBind(settings.queueName, settings.exchangeName, settings.routingKey, null);

            return _channel;
        }
开发者ID:alunwilliams,项目名称:RabbitMQTest,代码行数:25,代码来源:AmqpConnection.cs

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

示例11: Initialize

        public void Initialize(IModel channel, string mainQueue)
        {

            CreateExchange(channel, mainQueue);
            channel.QueueBind(mainQueue, mainQueue, string.Empty);

        }
开发者ID:MyDealerLot,项目名称:NServiceBus.RabbitMQ,代码行数:7,代码来源:ConventionalRoutingTopology.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: 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

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

示例15: DeclareAndBindQueueToExchange

 private static string DeclareAndBindQueueToExchange(IModel channel)
 {
     channel.ExchangeDeclare(ExchangeName, "fanout");
     var queueName = channel.QueueDeclare().QueueName;
     channel.QueueBind(queueName, ExchangeName, "");
     _consumer = new QueueingBasicConsumer(channel);
     return queueName;
 }
开发者ID:FantasticFiasco,项目名称:sandbox,代码行数:8,代码来源:Program.cs


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