示例#1
0
 private new EventHandlerFactoryList GetOrCreateHandlerFactories(Type eventType)
 {
     return HandlerFactories.GetOrAdd(eventType, (type) =>
     {
         var eventName = EventNameAttribute.GetNameOrDefault(type);
         EventTypes[eventName] = type;
         return new EventHandlerFactoryList();
     }) as EventHandlerFactoryList;
 }
示例#2
0
 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);
 }
示例#3
0
        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));
        }