HTML5¼¼Êõ

¡¶RabbitMQ Tutorial¡·ÒëÎÄ µÚ 3 Õ ·¢²¼ºÍ¶©ÔÄ - Ϫ±ß¾²ìø(3)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-12-14 16:00 ÎÒÒªÆÀÂÛ( )

The code for ReceiveLogs.cs: using System;using RabbitMQ.Client;using RabbitMQ.Client.Events;using System.Text;class ReceiveLogs{public static void Main(){var factory = new ConnectionFactory() { Host

The code for ReceiveLogs.cs:

using System; using RabbitMQ.Client; using RabbitMQ.Client.Events; using System.Text; class ReceiveLogs { public static void Main() { var factory = new ConnectionFactory() { HostName = "localhost" }; using(var connection = factory.CreateConnection()) using(var channel = connection.CreateModel()) { channel.ExchangeDeclare(exchange: "logs", type: "fanout"); var queueName = channel.QueueDeclare().QueueName; channel.QueueBind(queue: queueName, exchange: "logs", 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, autoAck: true, consumer: consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } } }

(ReceiveLogs.cs source)

Follow the setup instructions from tutorial one to generate the EmitLogs and ReceiveLogs projects.

´Ó½Ì³ÌµÄµÚÒ»Õ¿ªÊ¼£¬¸úË氲װ˵Ã÷À´Éú³É EmitLogs ºÍ ReceiveLogs ¹¤³Ì¡£

If you want to save logs to a file, just open a console and type:

Èç¹ûÄãÏë±£´æÈÕÖ¾µ½Ò»¸öÎļþ£¬Ö»Ðè´ò¿ª¿ØÖÆ̨²¢ÊäÈ룺

cd ReceiveLogs dotnet run > logs_from_rabbit.log

If you wish to see the logs on your screen, spawn a new terminal and run:

Èç¹ûÄãÏëÔÚÆÁÄ»Éϲ鿴ÈÕÖ¾£¬ÖØ¿ªÒ»¸öеÄÖն˲¢ÔËÐУº

cd ReceiveLogs dotnet run

And of course, to emit logs type:

µ±È»£¬²úÉúÈÕÖ¾Ö»ÐèÊäÈ룺

cd EmitLog dotnet run

Using rabbitmqctl list_bindings you can verify that the code actually creates bindings and queues as we want. With two ReceiveLogs.cs programs running you should see something like:

ʹÓà rabbitmqctl list_bindings ÃüÁîÄã¿ÉÒÔºËʵ´úÂëµÄÈ·ÒѾ­´´½¨ÁËÎÒÃÇÆÚÍûµÄ°ó¶¨ºÍ¶ÓÁУ¬°éËæ×Å ReceiveLogs.cs ³ÌÐòµÄÔËÐÐÄãÓ¦¸Ã¿ÉÒÔ¿´µ½ÀàËÆÈçÏÂÄÚÈÝ£º

sudo rabbitmqctl list_bindings # => Listing bindings ... # => logs exchange amq.gen-JzTY20BRgKO-HjmUJj0wLg queue [] # => logs exchange amq.gen-vso0PVvyiRIL2WoV3i48Yg queue [] # => ...done.

The interpretation of the result is straightforward: data from exchange logs goes to two queues with server-assigned names. And that's exactly what we intended.

¶Ô½á¹ûµÄ½âÊ;ͷdz£¼ò½àÃ÷ÁË£ºÀ´×Ô logs ½»»»»úµÄÊý¾Ý½«È¥ÍùÁ½¸öÓÉ·þÎñ¶Ë·ÖÅäÃû³ÆµÄ¶ÓÁУ¬¶øÕâÇ¡ºÃÊÇÎÒÃÇËùÆÚÍûµÄ¡£

posted @

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ¹ØÓÚ²©¿ÍÔ°Ê×Ò³·¢²¼¹æÔòµÄÈô¸É²Â²â - DOM¸ç

    ¹ØÓÚ²©¿ÍÔ°Ê×Ò³·¢²¼¹æÔòµÄÈô¸É²Â²â - DOM¸ç

    2017-12-05 16:08

  • ÌÚѶ·¢²¼ Omix 1.0 - Óà JSX »ò hyperscript ´´½¨Óû§½çÃæ - ¡¾µ±ÄÍÌØ¡¿

    ÌÚѶ·¢²¼ Omix 1.0 - Óà JSX »ò hyperscript ´´½¨Óû§½çÃæ - ¡¾µ±ÄÍ

    2017-08-08 17:00

  • ÌÚѶ AlloyCrop 1.0 ·¢²¼ - ¡¾µ±ÄÍÌØ¡¿

    ÌÚѶ AlloyCrop 1.0 ·¢²¼ - ¡¾µ±ÄÍÌØ¡¿

    2017-08-02 13:00

  • .NET Core 2.0 Preview2 ·¢²¼»ã×Ü - Savorboard

    .NET Core 2.0 Preview2 ·¢²¼»ã×Ü - Savorboard

    2017-07-01 11:01

ÍøÓѵãÆÀ
µ