コード例 #1
0
        void RegisterProcessor(IMessageQueueConsumer queueConsumer)
        {
            queueConsumer.Received += (sender, e) =>
            {
                logger.LogDebug($"消息接收成功,开始处理消息。 {e}");

                try
                {
                    processor.Process(e.QueueMessage);
                    queueConsumer.Commit();
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"已接收消息处理失败。 {e}");
                    queueConsumer.Reject();
                }
            };
            queueConsumer.Logged += (sender, e) =>
            {
                switch (e.LogType)
                {
                case MessageQueueLogType.KafkaOnConsumeError:
                    logger.LogError($"Kafka 消费异常。原因:{e.LogMessage}");
                    break;

                case MessageQueueLogType.KafkaOnError:
                    logger.LogError($"Kafka 连接异常。原因:{e.LogMessage}");
                    break;

                case MessageQueueLogType.RabbitMQConsumerCancelled:
                    logger.LogWarning($"RabbitMQ 消费者消费取消。 [ConsumerTag = {e.LogMessage}]");
                    break;

                case MessageQueueLogType.RabbitMQRegistered:
                    logger.LogDebug($"RabbitMQ 消费者注册成功。 [ConsumerTag = {e.LogMessage}]");
                    break;

                case MessageQueueLogType.RabbitMQShutdown:
                    logger.LogWarning($"RabbitMQ 消费者异常关闭!原因:{e.LogMessage}");
                    break;

                case MessageQueueLogType.RabbitMQUnregistered:
                    logger.LogWarning($"RabbitMQ 消费者未注册! [ConsumerTag = {e.LogMessage}]");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(e));
                }
            };
        }
コード例 #2
0
        private void InitQueues()
        {
            _coursesQueue         = new BasicMessageQueueConsumer <Course>();
            _coursesQueue.Get    += _coursesQueue_Get;
            _coursesQueue.GetAll += _coursesQueue_GetAll;
            _coursesQueue.Create += _coursesQueue_Create;
            _coursesQueue.Update += _coursesQueue_Update;
            _coursesQueue.Remove += _coursesQueue_Remove;

            _degreeProgramQueue         = new BasicMessageQueueConsumer <DegreeProgram>();
            _degreeProgramQueue.Get    += _degreeProgramQueue_Get;
            _degreeProgramQueue.GetAll += _degreeProgramQueue_GetAll;
            _degreeProgramQueue.Create += _degreeProgramQueue_Create;
            _degreeProgramQueue.Update += _degreeProgramQueue_Update;
            _degreeProgramQueue.Remove += _degreeProgramQueue_Remove;

            _electiveCourseQueue         = new BasicMessageQueueConsumer <ElectiveCourse>();
            _electiveCourseQueue.Get    += _electiveCourseQueue_Get;
            _electiveCourseQueue.GetAll += _electiveCourseQueue_GetAll;
            _electiveCourseQueue.Create += _electiveCourseQueue_Create;
            _electiveCourseQueue.Update += _electiveCourseQueue_Update;
            _electiveCourseQueue.Remove += _electiveCourseQueue_Remove;

            _electiveListQueue         = new BasicMessageQueueConsumer <ElectiveList>();
            _electiveListQueue.Get    += _electiveListQueue_Get;
            _electiveListQueue.GetAll += _electiveListQueue_GetAll;
            _electiveListQueue.Create += _electiveListQueue_Create;
            _electiveListQueue.Update += _electiveListQueue_Update;
            _electiveListQueue.Remove += _electiveListQueue_Remove;

            _electiveListCourseQueue         = new BasicMessageQueueConsumer <ElectiveListCourse>();
            _electiveListCourseQueue.Get    += _electiveListCourseQueue_Get;
            _electiveListCourseQueue.GetAll += _electiveListCourseQueue_GetAll;
            _electiveListCourseQueue.Create += _electiveListCourseQueue_Create;
            _electiveListCourseQueue.Update += _electiveListCourseQueue_Update;
            _electiveListCourseQueue.Remove += _electiveListCourseQueue_Remove;

            _planQueue         = new BasicMessageQueueConsumer <Plan>();
            _planQueue.Get    += _planQueue_Get;
            _planQueue.GetAll += _planQueue_GetAll;
            _planQueue.Create += _planQueue_Create;
            _planQueue.Update += _planQueue_Update;
            _planQueue.Remove += _planQueue_Remove;

            _planCourseQueue         = new BasicMessageQueueConsumer <PlanCourse>();
            _planCourseQueue.Get    += _planCourseQueue_Get;
            _planCourseQueue.GetAll += _planCourseQueue_GetAll;
            _planCourseQueue.Create += _planCourseQueue_Create;
            _planCourseQueue.Update += _planCourseQueue_Update;
            _planCourseQueue.Remove += _planCourseQueue_Remove;

            _prerequisiteCourseQueue         = new BasicMessageQueueConsumer <PrerequisiteCourse>();
            _prerequisiteCourseQueue.Get    += _prerequisiteCourseQueue_Get;
            _prerequisiteCourseQueue.GetAll += _prerequisiteCourseQueue_GetAll;
            _prerequisiteCourseQueue.Create += _prerequisiteCourseQueue_Create;
            _prerequisiteCourseQueue.Update += _prerequisiteCourseQueue_Update;
            _prerequisiteCourseQueue.Remove += _prerequisiteCourseQueue_Remove;

            _requiredCourseQueue         = new BasicMessageQueueConsumer <RequiredCourse>();
            _requiredCourseQueue.Get    += _requiredCourseQueue_Get;
            _requiredCourseQueue.GetAll += _requiredCourseQueue_GetAll;
            _requiredCourseQueue.Create += _requiredCourseQueue_Create;
            _requiredCourseQueue.Update += _requiredCourseQueue_Update;
            _requiredCourseQueue.Remove += _requiredCourseQueue_Remove;

            _semesterQueue         = new BasicMessageQueueConsumer <Semester>();
            _semesterQueue.Get    += _semesterQueue_Get;
            _semesterQueue.GetAll += _semesterQueue_GetAll;
            _semesterQueue.Create += _semesterQueue_Create;
            _semesterQueue.Update += _semesterQueue_Update;
            _semesterQueue.Remove += _semesterQueue_Remove;
        }