Exemple #1
0
        /// <summary>
        /// PublishAsync
        /// </summary>
        /// <param name="brokerName"></param>
        /// <param name="eventMessage"></param>
        /// <returns></returns>
        /// <exception cref="EventBusException"></exception>
        public async Task PublishAsync(string brokerName, string eventName, string jsonData)
        {
            RedisInstanceSetting instanceSetting = GetRedisInstanceSetting(brokerName);

            IDatabase database = await RedisInstanceManager.GetDatabaseAsync(instanceSetting, _logger).ConfigureAwait(false);

            EventMessageEntity entity = new EventMessageEntity(eventName, jsonData);

            await database.ListLeftPushAsync(QueueName(entity.EventName), SerializeUtil.ToJson(entity)).ConfigureAwait(false);
        }
Exemple #2
0
        internal static void InitLoadedLuas(RedisInstanceSetting redisInstanceSetting, ILogger logger)
        {
            IServer server = RedisInstanceManager.GetServer(redisInstanceSetting, logger);

            _loadedLuas = new LoadedLuas
            {
                LoadedLockLua   = server.ScriptLoad(_luaLock),
                LoadedUnLockLua = server.ScriptLoad(_luaUnlock),
                LoadedExtendLua = server.ScriptLoad(_luaExtend)
            };
        }
Exemple #3
0
        /// <summary>
        /// 每一种事件,只有一次SubscribeHandler的机会。之后再订阅,就报错了。
        /// 开始处理
        /// </summary>
        /// <exception cref="EventBusException"></exception>
        public void SubscribeHandler(string brokerName, string eventType, IEventHandler eventHandler)
        {
            RedisInstanceSetting instanceSetting = GetRedisInstanceSetting(brokerName);

            lock (_consumeTaskManagerLocker)
            {
                if (_consumeTaskManagers.ContainsKey(eventType))
                {
                    throw Exceptions.HandlerAlreadyExisted(eventType: eventType, brokerName: brokerName);
                }

                ConsumeTaskManager consumeTaskManager = new ConsumeTaskManager(_options, instanceSetting, _lockManager, eventType, eventHandler, _logger);

                _consumeTaskManagers.Add(eventType, consumeTaskManager);
            }
        }
        public ConsumeTaskManager(
            RedisEventBusOptions options,
            RedisInstanceSetting redisInstanceSetting,
            IDistributedLockManager lockManager,
            string eventType,
            IEventHandler eventHandler,
            ILogger logger)
        {
            _options         = options;
            _instanceSetting = redisInstanceSetting;
            _lockManager     = lockManager;

            _eventBusEventMessageExpiredSeconds = _options.EventBusEventMessageExpiredHours * 60 * 60;

            _eventType    = eventType;
            _eventHandler = eventHandler;
            _logger       = logger;

            _consumeTaskCTS = new CancellationTokenSource();

            _historyTaskCTS = new CancellationTokenSource();

            InitLodedLua();
        }
Exemple #5
0
 internal static IDatabase GetDatabase(RedisInstanceSetting redisInstanceSetting, ILogger logger)
 {
     return(RedisInstanceManager.GetDatabase(redisInstanceSetting, logger));
 }
Exemple #6
0
 internal static async Task <IDatabase> GetDatabaseAsync(RedisInstanceSetting redisInstanceSetting, ILogger logger)
 {
     return(await RedisInstanceManager.GetDatabaseAsync(redisInstanceSetting, logger).ConfigureAwait(false));
 }