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 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.