コード例 #1
0
        public void AutoSubscribe()
        {
            if (_isAutoSubscribed)
            {
                throw new System.InvalidOperationException("already automatic subscribed");
            }
            var messageTypes = _messageBus.GetAllHandledMessageTypes().ToList();

            foreach (var messageType in messageTypes)
            {
                var descriptor = _messageTopicResolver.Resolve(messageType);
                Logger.LogInformation($"AutoSubscribe: Found messageType:{messageType}, topic name: {descriptor?.MessageTopic}, group name: {descriptor?.MessageGroup}");
                _rabbitMQWrapper.Subscribe(descriptor, async(msg, _descriptor) => await _messageBus.OnMessageReceivedAsync(msg, _descriptor));
            }
            _isAutoSubscribed = true;
        }