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


C# IConnection.CreateModel方法代码示例

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


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

示例1: Telegraph

 public Telegraph()
 {
     var connectionFactory = new ConnectionFactory { HostName = "localhost", VirtualHost = "test" };
     _connection = connectionFactory.CreateConnection();
     _channel = _connection.CreateModel();
     _consumer = new QueueingBasicConsumer(_channel);
 }
开发者ID:bnathyuw,项目名称:Telegram,代码行数:7,代码来源:Telegraph.cs

示例2: RabbitMqMessageQueue

        public RabbitMqMessageQueue(string connectionString, string inputQueueName)
        {
            this.inputQueueName = inputQueueName;

            Log.Info("Opening Rabbit connection");
            connection = new ConnectionFactory {Uri = connectionString}.CreateConnection();

            Log.Debug("Creating model");
            model = connection.CreateModel();

            Log.Info("Initializing exchange and input queue");
            var tempModel = connection.CreateModel();

            Log.Debug("Ensuring that exchange exists with the name {0}", ExchangeName);
            tempModel.ExchangeDeclare(ExchangeName, ExchangeType.Topic, true);

            Log.Debug("Declaring queue {0}", this.inputQueueName);
            tempModel.QueueDeclare(this.inputQueueName, true, false, false, new Hashtable());

            Log.Debug("Binding {0} to {1} (routing key: {2})", this.inputQueueName, ExchangeName, this.inputQueueName);
            tempModel.QueueBind(this.inputQueueName, ExchangeName, this.inputQueueName);

            Log.Debug("Opening subscription");
            subscription = new Subscription(model, inputQueueName);
        }
开发者ID:karmerk,项目名称:Rebus,代码行数:25,代码来源:RabbitMqMessageQueue.cs

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

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

        public void Config()
        {
            var factory = new ConnectionFactory() { HostName = this.HostName };
            connection = factory.CreateConnection();
            channel1 = connection.CreateModel();
            channel1.QueueDeclare(queue: q1Name, durable: false, exclusive: false, autoDelete: false, arguments: null);

            channel2 = connection.CreateModel();
            channel2.QueueDeclare(queue: q2Name, durable: false, exclusive: false, autoDelete: false, arguments: null);
            consumer2 = new QueueingBasicConsumer(channel2);
            channel2.BasicConsume(queue: q2Name, noAck: true, consumer: consumer2);
        }
开发者ID:scott7950,项目名称:C_Sharp_RabbitMQ,代码行数:12,代码来源:ThreadClass.cs

示例6: OpenConnection

 private void OpenConnection()
 {
     connection = CreateConnectionFactory().CreateConnection();
     connection.ConnectionShutdown += ConnectionShutdown;
     model = connection.CreateModel();
     model.ExchangeDeclare(Exchange, ExchangeType, Durable);
 }
开发者ID:JohnBloom,项目名称:rabbitmq.log4net.gelf.appender,代码行数:7,代码来源:GelfRabbitMqAppender.cs

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

示例8: ProcessMessages

        public void ProcessMessages()
        {
            using (_connection = _factory.CreateConnection())
            {
                using (var channel = _connection.CreateModel())
                {
                    Console.WriteLine("Listening for Topic <payment.*>");
                    Console.WriteLine("------------------------------");
                    Console.WriteLine();
                    
                    channel.ExchangeDeclare(ExchangeName, "topic");
                    channel.QueueDeclare(AllQueueName, true, false, false, null);
                    channel.QueueBind(AllQueueName, ExchangeName, "payment.*");

                    channel.BasicQos(0, 10, false);
                    Subscription subscription = new Subscription(channel, AllQueueName, false);                    

                    while (true)
                    {
                        BasicDeliverEventArgs deliveryArguments = subscription.Next();
                        
                        var message = deliveryArguments.Body.DeSerializeText();

                        Console.WriteLine("Message Received '{0}'", message);
                        subscription.Ack(deliveryArguments);
                    }
                }
            }
        }
开发者ID:FantasticFiasco,项目名称:sandbox,代码行数:29,代码来源:RabbitMQConsumer.cs

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

示例10: EnsureConnectionOpen

        private IConnection EnsureConnectionOpen(IConnection connection)
        {
            IConnection ensuredConnection;

            try
            {
                var model = connection.CreateModel();

                model.Dispose();

                ensuredConnection = connection;
            }
            catch (Exception)
            {
                //TODO: Review this lock
                lock (_connections)
                {
                    _connections.Remove(connection);
                }

                ensuredConnection = GetConnection();
            }

            return ensuredConnection;
        }
开发者ID:vtex,项目名称:rabbitmq-abstraction,代码行数:25,代码来源:RabbitMQConnectionPool.cs

示例11: ProcessMessages

        public void ProcessMessages()
        {
            using (_connection = _factory.CreateConnection())
            {
                using (var channel = _connection.CreateModel())
                {
                    Console.WriteLine("Listening for Topic <payment.purchaseorder>");
                    Console.WriteLine("------------------------------------------");
                    Console.WriteLine();
                    
                    channel.ExchangeDeclare(ExchangeName, "topic");
                    channel.QueueDeclare(PurchaseOrderQueueName, true, false, false, null);
                    channel.QueueBind(PurchaseOrderQueueName, ExchangeName, "payment.purchaseorder");

                    channel.BasicQos(0, 10, false);
                    Subscription subscription = new Subscription(channel, PurchaseOrderQueueName, false);
                    
                    while (true)
                    {
                        BasicDeliverEventArgs deliveryArguments = subscription.Next();

                        var message = (PurchaseOrder)deliveryArguments.Body.DeSerialize(typeof(PurchaseOrder));
                        var routingKey = deliveryArguments.RoutingKey;

                        Console.WriteLine("-- Purchase Order - Routing Key <{0}> : {1}, £{2}, {3}, {4}", routingKey, message.CompanyName, message.AmountToPay, message.PaymentDayTerms, message.PoNumber);
                        subscription.Ack(deliveryArguments);
                    }
                }
            }
        }
开发者ID:FantasticFiasco,项目名称:sandbox,代码行数:30,代码来源:RabbitMQConsumer.cs

示例12: Bind

 /// <summary>
 /// Binds the queue to the exchange
 /// </summary>
 public static void Bind(IConnection connection, string queue, string exchange)
 {
     using(var m = connection.CreateModel())
     {
          m.QueueBind(queue, exchange, "", null);
     }
 }
开发者ID:jimitndiaye,项目名称:MassTransit,代码行数:10,代码来源:RabbitMqHelper.cs

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

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

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


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