public static void Main()
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
                         .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();

            ;
            var host = Environment.GetEnvironmentVariable("CLOUDAMQP_URL");

            if (string.IsNullOrEmpty(host))
            {
                host = config["Settings:RabbitMQCredentials:Host"];
            }
            var exchange      = config["Settings:RabbitMQCredentials:Exchange"];
            var retryExchange = exchange + ".retry";
            var queue         = config["Settings:RabbitMQCredentials:Queue"];
            var retryQueue    = queue + ".retry";
            var routingKey    = config["Settings:RabbitMQCredentials:RoutingKey"];
            var postProcessor = new RabbitMessageRePublisher(host, retryExchange, retryQueue, exchange, routingKey);
            var requester     = new PostRequester(postProcessor);

            using var consumer = new MessageConsumer(host, exchange, queue, routingKey, requester);
            consumer.Initialize();
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Consumer is starting...");
            var consumer = new MessageConsumer();

            consumer.MessageReceived += consumer_MessageReceived;
            Console.WriteLine("Consumer started.");

            Console.WriteLine("Waiting for messages...");
            consumer.StartReceiving();

            Console.WriteLine("Press Enter to stop receiving.");
            var input = Console.ReadLine();

            consumer.StopReceiving();
            Console.WriteLine("Consumer stopped receiving.");

            Console.WriteLine("Press Enter to exit.");
            Console.ReadLine();
        }