internal static ISubscriber BuildMessageHandler(IServiceProvider services, Type type)
        {
            var handler = (IMessageHandler <RabbitMQDelivery>)ActivatorUtilities.CreateInstance(services, type);

            if (handler is ISubscriber subscriber)
            {
                return(subscriber);
            }

            var acknowledgeMode      = AcknowledgeModeAttribute.FromType(type);
            var exceptionMode        = ExceptionModeAttribute.FromType(type);
            var subscription         = type.GetCustomAttribute <SubscribeAttribute>(true);
            var asyncContextAccessor = services.GetRequiredService <AsyncContextAccessor>();

            if (subscription == null)
            {
                var exchangeBinding = type.GetCustomAttribute <ExchangeBindingAttribute>(true);
                if (exchangeBinding != null)
                {
                    return(new ExchangeBindingSubscriber(
                               exchangeBinding.Exchange,
                               exchangeBinding.RoutingKey,
                               acknowledgeMode,
                               exceptionMode,
                               handler,
                               asyncContextAccessor));
                }

                subscription = SubscribeAttribute.FromType(type);
            }

            return(new QueueConsumerSubscriber(subscription.Queue, acknowledgeMode, exceptionMode, handler, asyncContextAccessor));
        }
        internal static ISubscriber BuildMessageHandlerToQueueDeclare(string queue, IServiceProvider services, Type type)
        {
            var handler = (IMessageHandler <RabbitMQDelivery>)ActivatorUtilities.CreateInstance(services, type);

            if (handler is ISubscriber subscriber)
            {
                return(subscriber);
            }

            var asyncContextAccessor = services.GetRequiredService <AsyncContextAccessor>();

            var acknowledgeMode = AcknowledgeModeAttribute.FromType(type);
            var exceptionMode   = ExceptionModeAttribute.FromType(type);

            return(new QueueConsumerSubscriber(queue, acknowledgeMode, exceptionMode, handler, asyncContextAccessor));
        }