Exemplo n.º 1
0
        private static Task RunAsync(IConfiguration config)
        {
            var handler = ConsumerContainer.Create(QueueNames.Book_Library, ExchangeNames.Book)
                          .Add <UpdateBookConsumer, BookMessage>("BookUpdateMessage")
                          .Build(config);

            return(handler.RunAsync());
        }
        private static Task RunAsync(IConfiguration configuration)
        {
            var handler = ConsumerContainer.Create(QueueNames.Book)
                          .Add <BookConsumer, BookMessage>()
                          .Build(configuration);

            return(handler.RunAsync());
        }
        private static Task RunAsync(IConfiguration config)
        {
            var handler = ConsumerContainer.Create(QueueNames.Bookstore)
                          .Add <PurchaseConsumer, PurchaseMessage>()
                          .Add <ShippingDtoConsumer, ShippingDtoMessage>()
                          .Build(config);

            return(handler.RunAsync());
        }
        private static Task RunAsync(IConfiguration config)
        {
            var handler = ConsumerContainer.Create(QueueNames.Library)
                          .Add <ReservationConsumer, ReservationMessage>()
                          .Add <ReservationDtoConsumer, ReservationDtoMessage>()
                          .Add <ReservationExpireConsumer, ReservationExpiredMessage>()
                          .Build(config);

            return(handler.RunAsync());
        }
        static void Main(string[] args)
        {
            using var producerFactory = new ProducerFactory("172.17.20.6:9876");

            using var consumerContainer = new ConsumerContainer("172.17.20.6:9876");

            TestConsumeMsg(consumerContainer, MsgTags[0]);
            TestPublishMsg(producerFactory);

            Console.ReadKey();
        }
        static void TestConsumeMsg(ConsumerContainer consumerContainer, params string[] msgTags)
        {
            consumerContainer.AddTopicConsumer("delay_order_create", "delay_msg_test", (q, ms) =>
            {
                var receiveTime = DateTime.Now;
                Console.WriteLine($"队列: {q}收到消息{ms.Length}条");

                foreach (var msg in ms)
                {
                    Console.WriteLine($"接收消息: {msg.Body.ToStr()}, Tags: {msg.Tags}, 产生时间: {msg.BornTimestamp.ToDateTime()}, 接收时间: {receiveTime}");
                }
                return(true);
            }, msgTags);
        }