private new EventHandlerFactoryList GetOrCreateHandlerFactories(Type eventType) { return HandlerFactories.GetOrAdd(eventType, (type) => { var eventName = EventNameAttribute.GetNameOrDefault(type); EventTypes[eventName] = type; return new EventHandlerFactoryList(); }) as EventHandlerFactoryList; }
public async Task PublishAsync(Type eventType, object eventData, MessageProperties properties, Dictionary<string, object> headersArguments = null) { var eventName = EventNameAttribute.GetNameOrDefault(eventType); var body = Serializer.Serialize(eventData); if (properties == null) { properties = new MessageProperties { DeliveryMode = 2, MessageId = Guid.NewGuid().ToString("N") }; } SetEventMessageHeaders(properties, headersArguments); await _bus.Advanced.PublishAsync(_exchange, eventName, true, properties, body); }
public override IDisposable Subscribe(Type eventType, IEventHandlerFactory factory) { GetOrCreateHandlerFactories(eventType) .Locking(factories => { factories.Add(factory); if (factories.Count == 1) { factories.Binding = _bus.Advanced.Bind(_exchange, _queue, EventNameAttribute.GetNameOrDefault(eventType)); } return factories; }); return new DisposeAction(() => Unsubscribe(eventType, factory)); }