1 using RabbitMQ.Client;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7
8 namespace RabbitMQTester
9 {
10 class Program
11 {
12 static void Main(string[] args)
13 {
14 try
15 {
16 ConnectionFactory factory = new ConnectionFactory()
17 {
18 UserName = "Freight",
19 Password = "Freight123.com!@#",
20 VirtualHost = "Freight",
21 Port = 5672,
22 AutomaticRecoveryEnabled = true,
23 TopologyRecoveryEnabled = true
24 };
25
26 IList<string> hostName = new List<string>() { "192.168.9.50", "192.168.9.51" };
27 var connection = factory.CreateConnection(hostName);
28 var channel = connection.CreateModel();
29 byte[] message = Encoding.UTF8.GetBytes(DateTime.Now.ToString());
30 channel.BasicPublish(string.Empty, "Test", null, message);
31
32 }
33 catch (Exception ex)
34 {
35 throw ex;
36 }
37 Console.ReadLine();
38 // 没有添加镜像之前: 关掉一台服务器 另一台 也无法使用
39 }
40 }
41 }