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


C# Client.QueueingBasicConsumer类代码示例

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


QueueingBasicConsumer类属于RabbitMQ.Client命名空间,在下文中一共展示了QueueingBasicConsumer类的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: Intitialize

        public void Intitialize()
        {
            var factory = new ConnectionFactory { HostName = "localhost" };
            using(var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare("Aimbase.Events", "direct");
                var consumer = new QueueingBasicConsumer(channel);

                foreach (var evnt in _eventHandlers)
                {
                    var queueName = channel.QueueDeclare().QueueName;

                    channel.QueueBind(queueName, "Aimbase.Events", evnt.Type);

                    channel.BasicConsume(queueName, true, consumer);
                }

                while (true)
                {
                    var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);

                    foreach (var eventHandler in _eventHandlers.Where(eh => eh.Type == ea.RoutingKey))
                    {
                        eventHandler.Handle(message);
                    }
                }
            }
        }
开发者ID:ScottIsaak,项目名称:eventstore,代码行数:32,代码来源:EventBroker.cs

示例3: Main

        private static void Main(string[] args)
        {
            Console.WriteLine("Ready to start charging for orders - press <enter> to stacking up cash...");
            Console.ReadLine();

            var factory = new ConnectionFactory { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    var queueName = channel.QueueDeclare().QueueName;
                    channel.QueueBind(queueName, ExchangeName, "");

                    var consumer = new QueueingBasicConsumer(channel);
                    channel.BasicConsume(queueName, true, consumer);

                    Console.WriteLine("Waiting for work - press <ctrl-c> to shut down...");
                    while (true)
                    {
                        var message = consumer.Queue.Dequeue();

                        var body = message.Body;
                        var contents = Encoding.UTF8.GetString(body);

                        int quantity = int.Parse(contents.Split(' ')[0]);
                        Console.WriteLine("Charging for {0} widgets.", quantity);
                    }
                }
            }
        }
开发者ID:ekepes,项目名称:Presentations,代码行数:30,代码来源:Program.cs

示例4: Main

		private static void Main(string[] args)
		{
			var factory = new ConnectionFactory
			{
				HostName = "localhost",
				UserName = "guest",
				Password = "guest",
				Protocol = Protocols.DefaultProtocol
			};

			using (var c = factory.CreateConnection())
			using (var m = c.CreateModel())
			{
				var consumer = new QueueingBasicConsumer(m);
				var props = new Dictionary<string, object>()
				{
				    {"x-expires", 30*60000} // expire queue after 30 minutes, see http://www.rabbitmq.com/extensions.html
				};
				var q = m.QueueDeclare("", false, true, false, props);

				m.QueueBind(q, "log4net-logging", "#");
				m.BasicConsume(q, true, consumer);
				
				while (true)
				{
					var msg = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
					
					if (msg.BasicProperties.IsAppIdPresent())
						Console.Write(msg.BasicProperties.AppId + " ");

					Console.Write(msg.Body.AsUtf8String());
				}
			}
		}
开发者ID:mondok,项目名称:log4net.RabbitMQ,代码行数:34,代码来源:Program.cs

示例5: WorkerThreadFunc

        private static void WorkerThreadFunc()
        {
            var factory = new ConnectionFactory { HostName = "127.0.0.1" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {

                // mark all messages as persistent
                const bool durable = true;
                channel.QueueDeclare(QueueName, durable, false, false, null);

                var consumer = new QueueingBasicConsumer(channel);

                // turn auto acknowledge off so we can do it manually
                const bool autoAck = false;
                channel.BasicConsume(QueueName, autoAck, consumer);

                while (true)
                {
                    var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

                    byte[] body = ea.Body;
                    var message = System.Text.Encoding.UTF8.GetString(body);

                    Thread.Sleep(5000);

                    channel.BasicAck(ea.DeliveryTag, false);
                }
            }
        }
开发者ID:mplacona,项目名称:RabbitMQ-Integration,代码行数:30,代码来源:ReceiverService.cs

示例6: NextAsync

        public Task<PollerResult<Event>> NextAsync(QueueName name)
        {
            var connection = _connectionProvider.GetConnection();
            var result = new PollerResult<Event>(false , Event.Empty);
            using (var channel = connection.CreateModel())
            {
                var consumer = new QueueingBasicConsumer(channel);
                channel.BasicConsume(name.SubscriptionName, true, consumer);
                BasicDeliverEventArgs eventArgs = null;
                if (consumer.Queue.Dequeue((int)_longPollingTimeout.TotalMilliseconds, 
                    out eventArgs))
                {
                    var @event = new Event()
                    {
                        Body = Encoding.UTF8.GetString(eventArgs.Body),
                        QueueName = name.SubscriptionName,
                        UnderlyingMessage = eventArgs,
                        ContentType = "text/plain", // should it be JSON?
                        EventType = name.SubscriptionName
                    };

                    result = new PollerResult<Event>(true, @event);
                }
                return Task.FromResult(result);
            }

        }
开发者ID:csuffyy,项目名称:BeeHive,代码行数:27,代码来源:RabbitMqOperator.cs

示例7: Main

        public static void Main()
        {
            ConnectionFactory factory = new ConnectionFactory();
            factory.HostName = "localhost";
            using (IConnection connection = factory.CreateConnection())
            using (IModel channel = connection.CreateModel())
            {
                channel.QueueDeclare("start", false, false, false, null);

                QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
                channel.BasicConsume("start", true, consumer);

                System.Console.WriteLine(" [*] Waiting for messages." +
                                         "To exit press CTRL+C");
                while (true)
                {
                    BasicDeliverEventArgs ea =
                        (BasicDeliverEventArgs)consumer.Queue.Dequeue();

                    byte[] body = ea.Body;
                    string message = System.Text.Encoding.UTF8.GetString(body);
                    System.Console.WriteLine(" [x] Received {0}", message);
                }
            }
        }
开发者ID:3agrey,项目名称:RabbitMQ,代码行数:25,代码来源:Receiver.cs

示例8: Main

        private static void Main(string[] args)
        {
            Console.WriteLine("Logger waiting for messages...");

            var factory = new ConnectionFactory { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(ExchangeName, "topic");

                    var queueName = channel.QueueDeclare().QueueName;
                    channel.QueueBind(queueName, ExchangeName, "ewk.#");

                    var consumer = new QueueingBasicConsumer(channel);
                    channel.BasicConsume(queueName, true, consumer);

                    int logEntry = 0;
                    Console.WriteLine("Waiting for work - press <ctrl-c> to shut down...");
                    while (true)
                    {
                        var message = consumer.Queue.Dequeue();

                        var body = message.Body;
                        var contents = Encoding.UTF8.GetString(body);

                        Console.WriteLine("[{0}:{1:yyyyMMdd-HHmmss.fffff}] {2}",
                            logEntry++, DateTimeOffset.Now, contents);
                    }
                }
            }
        }
开发者ID:ekepes,项目名称:Presentations,代码行数:32,代码来源:Program.cs

示例9: receive

    /*
        This method is receiving request from the server
    */
    public void receive()
    {
        DateTime date_ini = DateTime.Now;
        this.factory.HostName = c_reader.GetServer();

        using (var connection = this.factory.CreateConnection())
        {

            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare("transmission", "fanout");

                var queueName = channel.QueueDeclare().QueueName;
                channel.QueueBind(queueName, "transmission", "");

                var consumer = new QueueingBasicConsumer(channel);
                channel.BasicConsume(queueName, true, consumer);

                Console.WriteLine(" [*] Waiting for logs." +
                                  " To exit press CTRL+C");

                while (true)
                {
                    var event_args = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                    var body = event_args.Body;
                    var message = Encoding.UTF8.GetString(body);

                    Console.WriteLine(" [x] {0}", message);
                    //method to storage the message into the database
                    StoreData(message);

                }
            }
        }
    }
开发者ID:ZelmaJenifer,项目名称:Distributed-systems,代码行数:38,代码来源:Receiver.cs

示例10: Main

        static void Main()
        {
            _factory = new ConnectionFactory { HostName = "localhost", UserName = "guest", Password = "guest" };
            using (_connection = _factory.CreateConnection())
            {
                using (var channel = _connection.CreateModel())
                {
                    channel.ExchangeDeclare(ExchangeName, "direct");
                    channel.QueueDeclare(CardPaymentQueueName, true, false, false, null);
                    channel.QueueBind(CardPaymentQueueName, ExchangeName, "CardPayment");
                    channel.BasicQos(0, 1, false);

                    var consumer = new QueueingBasicConsumer(channel);
                    channel.BasicConsume(CardPaymentQueueName, false, consumer);

                    while (true)
                    {                        
                        var ea = consumer.Queue.Dequeue();
                        var message = (Payment)ea.Body.DeSerialize(typeof(Payment));                        
                        var routingKey = ea.RoutingKey;
                        channel.BasicAck(ea.DeliveryTag, false);
                        Console.WriteLine("--- Payment - Routing Key <{0}> : {1} : {2}", routingKey, message.CardNumber, message.AmountToPay);
                    }
                }
            }
        }
开发者ID:FantasticFiasco,项目名称:sandbox,代码行数:26,代码来源:Program.cs

示例11: 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 );
            var consumer = new QueueingBasicConsumer( channel );
            channel.BasicConsume( queue: "task_queue", noAck: false, consumer: consumer );

            Console.WriteLine( " [*] Waiting for messages. To exit press CTRL+C" );
            while( true )
            {
                var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

                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 );
            }
        }
    }
开发者ID:zhaoshiling1017,项目名称:rabbitmq-tutorials,代码行数:30,代码来源:Worker.cs

示例12: Run

        public void Run()
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: "perf", type: "fanout");

                    var queueName = channel.QueueDeclare().QueueName;

                    channel.QueueBind(queue: queueName, exchange: "perf", routingKey: "");
                    var consumer = new QueueingBasicConsumer(channel);
                    channel.BasicConsume(queueName, true, consumer);

                    Console.WriteLine(" [*] Waiting for perf. To exit press CTRL+C");
                    timer.Start();
                    while (true)
                    {
                        var ea = consumer.Queue.Dequeue();

                        var body = ea.Body;
                        var message = Encoding.UTF8.GetString(body);
                        receivedMessages += 1;
                    }
                }
            }
        }
开发者ID:sam-io,项目名称:dotnet-playground,代码行数:28,代码来源:Program.cs

示例13: ConsumeMessages

        private void ConsumeMessages(string queueName)
        {
            using (IConnection conn = factory.CreateConnection())
            {
                using (IModel channel = conn.CreateModel())
                {
                    var consumer = new QueueingBasicConsumer(channel);
                    channel.BasicConsume(queueName, false, consumer);
                    Trace.WriteLine(string.Format("Waiting for messages from: {0}", queueName));

                    while (true)
                    {
                        BasicDeliverEventArgs ea = null;
                        try
                        {
                            ea = consumer.Queue.Dequeue();
                        }
                        catch (EndOfStreamException endOfStreamException)
                        {
                            Trace.WriteLine(endOfStreamException);
                        }
                        if (ea == null) break;
                        var body = ea.Body;
                        var receivedMessage = _serializer.Deserialie<NotificationMessage>(body);
                        Trace.WriteLine(
                            string.Format(
                                "Message Received: {0} From: {1}, To: {2} on Thread: {3} with CorrelationId: {4} and DeliveryTag: {5}",
                                receivedMessage.Message, receivedMessage.Source, receivedMessage.Target,
                                Thread.CurrentThread.ManagedThreadId, ea.BasicProperties.CorrelationId, ea.DeliveryTag));
                        Thread.Sleep(300);
                        channel.BasicAck(ea.DeliveryTag, false);
                    }
                }
            }
        }
开发者ID:njfife,项目名称:playground,代码行数:35,代码来源:UlakTests.cs

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

示例15: Main

        static void Main(string[] args)
        {
            var exchg = "socketIOdemo";
            var queue = "socketIOdemoNetQ";

            var ser = new JavaScriptSerializer();
            var factory = new ConnectionFactory();
            factory.Protocol = Protocols.FromEnvironment();
            factory.HostName = "localhost";
            using (var con = factory.CreateConnection())
            using (var mod = con.CreateModel())
            {
                mod.QueueDeclare(queue, true, false, false, null);
                mod.ExchangeDeclare(exchg, ExchangeType.Fanout, true);
                mod.QueueBind(queue, exchg, string.Empty);

                var consumer = new QueueingBasicConsumer(mod);
                mod.BasicConsume(queue, false, consumer);
                Console.WriteLine("Waiting for messages...");
                while (true)
                {
                    var e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                    mod.BasicAck(e.DeliveryTag, false);
                    var props = e.BasicProperties;
                    byte[] body = e.Body;
                    var msg = ser.Deserialize<Message>(Encoding.UTF8.GetString(body));
                    Console.WriteLine(DateTime.Now.ToShortTimeString()+">> " + msg.body);
                }
            }
        }
开发者ID:bmegias,项目名称:SocketIOClient,代码行数:30,代码来源:Program.cs


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