示例#1
0
 private void SetHandlers <T>(Action <T> handlers, string topic = null, EventBusType eventBusType = EventBusType.ArgType)
 {
     if (eventBusType == EventBusType.ArgType)
     {
         eventMap[typeof(T)] = handlers;
     }
     else if (eventBusType == EventBusType.Topic)
     {
         eventTopicMap[topic] = handlers;
     }
 }
        protected BaseEventBusTests(EventBusType eventBusType)
        {
            eventReceivedNotifier = new EventReceivedNotifier();
            integerIncrementer    = new IntegerIncrementer();
            autoResetEvent        = new AutoResetEvent(false);
            eventReceivedNotifier.OnEventReceived += (s, e) =>
            {
                autoResetEvent.Set();
            };
            var services = SetupServices();

            eventBus = SetupEventBus(services, eventBusType);
        }
示例#3
0
        private void ModfyHandler <T>(Action <T> eventHandler, string topic = null, EventBusType eventBusType = EventBusType.ArgType, bool isAdd = true)
        {
            Action <T> handlers = GetHandlers <T>(topic, eventBusType);

            if (isAdd)
            {
                handlers += eventHandler;
            }
            else
            {
                handlers -= eventHandler;
            }
            SetHandlers <T>(handlers, topic, eventBusType);
        }
示例#4
0
 private Action <T> GetHandlers <T>(string topic = null, EventBusType eventBusType = EventBusType.ArgType)
 {
     if (eventBusType == EventBusType.ArgType)
     {
         if (!eventMap.ContainsKey(typeof(T)))
         {
             eventMap[typeof(T)] = null;
         }
         return((Action <T>)eventMap[typeof(T)]);
     }
     else
     {
         if (!eventTopicMap.ContainsKey(topic))
         {
             eventTopicMap[topic] = null;
         }
         return((Action <T>)eventTopicMap[topic]);
     }
 }
        private static IEventBus SetupEventBus(ServiceCollection services, EventBusType eventBusType)
        {
            switch (eventBusType)
            {
            case EventBusType.RabbitMQ:
                services.AddRabbitMQ(new RabbitMQOptions()
                {
                    ExchangeName = "Exchange",
                    QueueName    = "IntegrationTests",
                    UserName     = "******",
                    Password     = "******"
                });
                break;

            case EventBusType.In_Memory:
                services.AddInMemoryEventBus();
                break;

            case EventBusType.Azure:
                services.AddAzureServiceBus(new AzureServiceBusOptions()
                {
                    SubscriptionName = "IntegrationTest",
                    ConnectionString = "Endpoint=sb://finaps-bus.servicebus.windows.net/;SharedAccessKeyName=IntegrationTest;SharedAccessKey=x55a0K04JdGS+5/uFNTw99raxFFUY5T7iq2UFBbZbBg=;EntityPath=test"
                });
                break;
            }


            var serviceProvider = new DefaultServiceProviderFactory().CreateServiceProvider(services);
            var eventBus        = serviceProvider.GetRequiredService <IEventBus>();

            eventBus.Subscribe <EventPublisherEvent, EventPublisherEventHandler>();
            eventBus.Subscribe <SubscriptionTestEvent, SubscriptionTestEventHandler>();
            eventBus.Subscribe <CheckConcurrencyEvent, CheckConcurrencyEventHandler>();
            return(eventBus);
        }