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

namespace Consumer3
{
    public class Message : IMessageA
    {
        public string Text { get; set; }
    }
    public class MessageConsumer : IConsumer<IMessageA>
    {
        public async Task Consume(ConsumeContext<IMessageA> context)
            => Console.WriteLine($"test-queue-3 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-3";

            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.UseMessageRetry(r => r.Immediate(5));
                factory.UseRateLimit(1000, TimeSpan.FromMinutes(1));
            });

            await bus.StartAsync();
            Console.ReadLine();
            await bus.StopAsync();
        }
    }
}
