Beispiel #1
0
        static async Task Main(string[] args)
        {
            var host = new ServiceHost();

            host.AddJsonConfiguration("Config.json");
            host.ConfigureRabbitMQ("MQ");
            host.OnHostStarted += p =>
            {
                var s = p.GetRabbitMQ();
                // 创建交换机
                s.ExchangeDeclare("exchange.direct", ExchangeType.Direct);
                // 创建队列
                s.QueueDeclare("queueA", true);
                // 绑定
                s.QueueBind("queueA", "exchange.direct", "A");
                // 订阅
                s.Subscribe("queueA", true, (m, a) => Console.WriteLine(Encoding.UTF8.GetString(a.Body.ToArray())));
                // 发布消息
                s.Publish(new
                {
                    Id   = 1,
                    Name = "Joy"
                }, "exchange.direct", "A");
            };
            await host.RunAsync();
        }
Beispiel #2
0
 /// <summary>
 /// 配置RabbitMQ
 /// </summary>
 /// <param name="host"></param>
 /// <param name="stream"></param>
 /// <param name="path"></param>
 /// <returns></returns>
 public static ServiceHost ConfigureRabbitMQWithXml(this ServiceHost host, Stream stream, string path = null)
 => host.ConfigureRabbitMQ(new ConfigurationBuilder().AddXmlStream(stream).Build(), path);
Beispiel #3
0
 /// <summary>
 /// 配置RabbitMQ
 /// </summary>
 /// <param name="host"></param>
 /// <param name="file"></param>
 /// <param name="path"></param>
 /// <returns></returns>
 public static ServiceHost ConfigureRabbitMQWithXml(this ServiceHost host, string file, string path = null)
 => host.ConfigureRabbitMQ(new ConfigurationBuilder().AddXmlFile(file).Build(), path);