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

namespace Consumer1
{
    public class MessageA : IMessageA
    {
        public string Text { get; set; }
    }
    public class MessageAConsumer : IConsumer<IMessageA>
    {
        public async Task Consume(ConsumeContext<IMessageA> context)
            => Console.WriteLine($"Gelen mesaj : {context.Message.Text}");
    }
    public class MessageB : IMessageB
    {
        public string Text { get; set; }
    }
    public class MessageBConsumer : IConsumer<IMessageB>
    {
        public async Task Consume(ConsumeContext<IMessageB> context)
            => Console.WriteLine($"Gelen mesaj : {context.Message.Text}");
    }
    public class MessageC : IMessageC
    {
        public string Text { get; set; }
    }
    public class MessageCConsumer : IConsumer<IMessageC>
    {
        public async Task Consume(ConsumeContext<IMessageC> context)
            => Console.WriteLine($"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-1";

            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<MessageAConsumer>();
                    endpoint.Consumer(() => new MessageBConsumer());
                    endpoint.Consumer(typeof(MessageCConsumer), type => Activator.CreateInstance(type));
                });
            });
            await bus.StartAsync();
            Console.ReadLine();
            await bus.StopAsync();
        }
    }
}
