protected override async ValueTask ProcessEvent(string routingKey, string eventName, ReadOnlyMemory <byte> message, CancellationToken cancel = default)
        {
            if (SubsManager.HasSubscriptionsForEvent(routingKey))
            {
                var subscriptions = SubsManager.GetHandlersForEvent(routingKey);
                foreach (var subscription in subscriptions)
                {
                    switch (subscription.SubscriptionManagerType)
                    {
                    case SubscriptionManagerType.Queue:
                        try
                        {
                            if (EventHandler is null)
                            {
                            }
                            else
                            {
                                var eventType = SubsManager.GetEventTypeByName(routingKey);
                                await using var ms = new MemoryStream(message.ToArray());
                                var integrationEvent = Serializer.Deserialize(eventType, ms);
                                var concreteType     = typeof(IIntegrationQueueHandler <>).MakeGenericType(eventType);
                                await((ValueTask <bool>)concreteType.GetMethod("Enqueue")
                                      .Invoke(EventHandler, new[] { integrationEvent, cancel })).ConfigureAwait(false);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError("ProcessQueue: " + ex.Message + " - " + ex.StackTrace);
                        }
                        break;


                    case SubscriptionManagerType.Dynamic:
                        break;

                    case SubscriptionManagerType.Typed:
                        break;

                    case SubscriptionManagerType.Rpc:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }//ProcessEvent.
        private void DoInternalSubscriptionRpc(string eventName, string eventNameResult)
        {
            var containsKey = SubsManager.HasSubscriptionsForEvent(eventName);

            if (containsKey)
            {
                return;
            }
            if (!PersistentConnection.IsConnected)
            {
                PersistentConnection.TryConnect();
            }

            using var channel = PersistentConnection.CreateModel();
            channel.QueueBind(QueueName, ExchangeDeclareParameters.ExchangeName, eventName);
            channel.QueueBind(_queueNameReply, ExchangeDeclareParameters.ExchangeName, eventNameResult);
        }
        private async ValueTask <dynamic> ProcessEventRpc(string routingKey, string eventName, ReadOnlyMemory <byte> message, CancellationToken cancel = default)
        {
            dynamic output = null;

            if (SubsManager.HasSubscriptionsForEvent(routingKey))
            {
                var subscriptions = SubsManager.GetHandlersForEvent(routingKey);

                if (!subscriptions.Any())
                {
                    Logger.LogError("ProcessEventRpc subscriptions no items! " + routingKey);
                }
                foreach (var subscription in subscriptions)
                {
                    switch (subscription.SubscriptionManagerType)
                    {
                    case SubscriptionManagerType.Rpc:
                        try
                        {
                            if (EventHandler is null)
                            {
                                Logger.LogError("ProcessEventRpc _eventHandler is null!");
                            }
                            else
                            {
                                var eventType = SubsManager.GetEventTypeByName(routingKey);
                                if (eventType is null)
                                {
                                    Logger.LogError("ProcessEventRpc: eventType is null! " + routingKey);
                                    return(null);
                                }
                                var eventReplyType = SubsManager.GetEventReplyTypeByName(routingKey);
                                if (eventReplyType is null)
                                {
                                    Logger.LogError("ProcessEventRpc: eventReplyType is null! " + routingKey);
                                    return(null);
                                }

                                using (var ms = new MemoryStream(message.ToArray()))
                                {
                                    var integrationEvent = Serializer.Deserialize(eventType, ms);
                                    var concreteType     =
                                        typeof(IIntegrationRpcHandler <,>).MakeGenericType(eventType,
                                                                                           eventReplyType);

                                    output = await((dynamic)concreteType.GetMethod("HandleRpcAsync")
                                                   .Invoke(EventHandler, new[] { integrationEvent, cancel })).ConfigureAwait(false);

                                    if (output is null)
                                    {
                                        Logger.LogError("ProcessEventRpc output is null!");
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError("ProcessEventRpc: " + ex.Message + " - " + ex.StackTrace);
                        }
                        break;

                    case SubscriptionManagerType.Dynamic:
                        break;

                    case SubscriptionManagerType.Typed:
                        break;

                    case SubscriptionManagerType.Queue:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
            else
            {
                Logger.LogError("ProcessEventRpc HasSubscriptionsForEvent " + routingKey + " No Subscriptions!");
            }
            return(output);
        }//ProcessEventRpc.
        protected override async ValueTask ProcessEvent(string routingKey, string eventName, ReadOnlyMemory <byte> message, CancellationToken cancel = default)
        {
            if (SubsManager.HasSubscriptionsForEvent(routingKey))
            {
                if (_autofac != null)
                {
                    await using var scope = _autofac.BeginLifetimeScope(AutofacScopeName);
                    var subscriptions = SubsManager.GetHandlersForEvent(routingKey);
                    foreach (var subscription in subscriptions)
                    {
                        //if (subscription.IsDynamic)
                        //{
                        //    var handler =
                        //        scope.ResolveOptional(subscription.HandlerType) as IDynamicIntegrationEventHandler;

                        //    //ToDo
                        //    //dynamic eventData = JObject.Parse(message);

                        //    //await using var ms = new MemoryStream(message);
                        //    //var integrationEvent = Serializer.Deserialize(eventType, ms);

                        //    //await handler.Handle(eventData);
                        //}
                        //else
                        //{
                        //    var eventType = _subsManager.GetEventTypeByName(routingKey);
                        //    //var integrationEvent = JsonConvert.DeserializeObject(message, eventType);

                        //    await using var ms = new MemoryStream(message);
                        //    var integrationEvent = Serializer.Deserialize(eventType, ms);

                        //    var handler = scope.ResolveOptional(subscription.HandlerType);
                        //    var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType);
                        //    await (ValueTask) concreteType.GetMethod("Handle")
                        //        .Invoke(handler, new[] {integrationEvent});
                        //}

                        switch (subscription.SubscriptionManagerType)
                        {
                            //case InMemoryEventBusSubscriptionsManager.SubscriptionManagerType.Dynamic:
                            //    var handler =
                            //        scope.ResolveOptional(subscription.HandlerType) as IDynamicIntegrationEventHandler;

                            //    //ToDo
                            //    //dynamic eventData = JObject.Parse(message);

                            //    await using var ms = new MemoryStream(message);
                            //    var integrationEvent = Serializer.Deserialize(eventType, ms);

                            //    await handler.Handle(eventData);
                            //    break;

                            //default:
                            //    {
                            //        var eventType = _subsManager.GetEventTypeByName(routingKey);
                            //        //var integrationEvent = JsonConvert.DeserializeObject(message, eventType);

                            //        await using var ms = new MemoryStream(message);
                            //        var integrationEvent = Serializer.Deserialize(eventType, ms);

                            //        var handler = scope.ResolveOptional(subscription.HandlerType);
                            //        var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType);
                            //        await (ValueTask)concreteType.GetMethod("Handle")
                            //            .Invoke(handler, new[] { integrationEvent, cancel });
                            //        break;
                            //    }
                        }
                    }
                }
            }
        }//ProcessEvent.