using GreenPipes;
using MassTransit;
using Shared;
using System;
using System.Threading.Tasks;

namespace Consumer2
{
    public class MessageA : IMessageA
    {
        public string Text { get; set; }
    }
    public class MessageConsumer : IConsumer<IMessageA>
    {
        public async Task Consume(ConsumeContext<IMessageA> context)
            => Console.WriteLine($"test-queue-2 Gelen mesaj : {context.Message.Text}");
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            string rabbitMqUri = "amqps://wmfjyalu:X0GmitgZM7iXUPmT4uymccexqiTKoxJq@shark.rmq.cloudamqp.com/wmfjyalu";
            string queue = "test-queue-2";

            string userName = "wmfjyalu";
            string password = "X0GmitgZM7iXUPmT4uymccexqiTKoxJq";

            var bus = Bus.Factory.CreateUsingRabbitMq(factory =>
            {
                factory.Host(rabbitMqUri, configurator =>
                {
                    configurator.Username(userName);
                    configurator.Password(password);
                });

                factory.ReceiveEndpoint(queue, endpoint => endpoint.Consumer<MessageConsumer>());
                factory.UseCircuitBreaker(configurator =>
                {
                    configurator.TrackingPeriod = TimeSpan.FromMinutes(1);
                    configurator.TripThreshold = 15;
                    configurator.ActiveThreshold = 10;
                    configurator.ResetInterval = TimeSpan.FromMinutes(5);
                });
            });
            await bus.StartAsync();
            Console.ReadLine();
            await bus.StopAsync();
        }
    }
}