public Task Handle(StartSagaMessage message, IMessageHandlerContext context)
                {
                    TestContext.InterceptingHandlerCalled = true;
                    context.DoNotContinueDispatchingCurrentMessageToHandlers();

                    return Task.FromResult(0);
                }
コード例 #2
0
                public Task Handle(SomeMessage message, IMessageHandlerContext context)
                {
                    Context.FirstHandlerInvoked = true;

                    context.DoNotContinueDispatchingCurrentMessageToHandlers();

                    return(Task.FromResult(0));
                }
            public async Task Handle(SomeCommand message, IMessageHandlerContext context)
            {
                await context.Send(new SomeCommand());

                await context.Publish(new SomeEvent());

                await uniformSession.Send(new SomeCommand());

                await uniformSession.Publish(new SomeEvent());

                context.DoNotContinueDispatchingCurrentMessageToHandlers();
            }
コード例 #4
0
            public Task Handle(OrderMessage message, IMessageHandlerContext context)
            {
                var session = context.SynchronizedStorageSession.MyOrmSession();
                var order   = session.Get(message.OrderId);

                if (this.MessageHasAlreadyBeenProcessed(context.MessageId, order))
                {
                    //Subsequent handlers are not invoked because the message has already been processed.
                    context.DoNotContinueDispatchingCurrentMessageToHandlers();
                }
                else
                {
                    this.MarkAsProcessed(context.MessageId, order);
                }
                return(Task.CompletedTask);
            }
コード例 #5
0
        public static async Task <bool> Defer(this IMessageHandlerContext context, object message, TimeSpan delay, string retriesKey, int maxnumberOfRetries = 5)
        {
            var retriesHeader = context.MessageHeaders.ContainsKey(retriesKey) ? context.MessageHeaders[retriesKey] : null;
            var retries       = string.IsNullOrEmpty(retriesHeader) ? 0 : int.Parse(retriesHeader);

            if (++retries > maxnumberOfRetries)
            {
                return(false);
            }

            var options = new SendOptions();

            options.DelayDeliveryWith(delay);
            options.SetHeader(retriesKey, retries.ToString());
            await context.Send(message, options).ConfigureAwait(false);

            context.DoNotContinueDispatchingCurrentMessageToHandlers();
            return(true);
        }
コード例 #6
0
        public async Task Handle(ProcessLearnerCommand message, IMessageHandlerContext context)
        {
            logger.LogDebug($"Handling ILR learner submission. Job: {message.JobId}, Ukprn: {message.Ukprn}, Collection year: {message.CollectionYear}, Learner: {message.Learner.LearnRefNumber}");
            var processorResult = learnerSubmissionProcessor.GenerateEarnings(message);

            if (processorResult.Validation.Failed)
            {
                logger.LogInfo($"ILR Learner Submission failed validation. Job: {message.JobId}, Ukprn: {message.Ukprn}, Collection year: {message.CollectionYear}, Learner: {message.Learner.LearnRefNumber}");
                context.DoNotContinueDispatchingCurrentMessageToHandlers();
                return;
            }

            foreach (var earningEvent in processorResult.EarningEvents)
            {
                await context.Publish(earningEvent).ConfigureAwait(false);
            }
            var summary = string.Join(", ", processorResult.EarningEvents.GroupBy(e => e.GetType().Name).Select(g => $"{g.Key}: {g.Count()}"));

            logger.LogInfo($"Finished handling ILR learner submission.Job: { message.JobId}, Ukprn: { message.Ukprn}, Collection year: { message.CollectionYear}, Learner: { message.Learner.LearnRefNumber}. Published events: {summary}");
        }
コード例 #7
0
        public async Task Handle(SubmissionJobSucceeded message, IMessageHandlerContext context)
        {
            var delay = TimeSpan.Parse(
                configurationHelper.GetSettingOrDefault("MetricsGenerationDelay", "00:05:00"));

            logger.LogDebug($"Delaying metrics generation for {delay.TotalSeconds} seconds for job: {message.JobId}");
            var options = new SendOptions();

            options.RouteToThisEndpoint();
            options.DelayDeliveryWith(delay);
            await context.Send(new GenerateSubmissionSummary
            {
                CollectionPeriod = message.
                                   CollectionPeriod,
                JobId        = message.JobId,
                Ukprn        = message.Ukprn,
                AcademicYear = message.AcademicYear
            }, options).ConfigureAwait(false);

            context.DoNotContinueDispatchingCurrentMessageToHandlers();
            logger.LogInfo($"Delayed metrics generation for {delay.TotalSeconds} seconds for job: {message.JobId}");
        }
コード例 #8
0
            public Task Handle(TestMessage message, IMessageHandlerContext context)
            {
                context.DoNotContinueDispatchingCurrentMessageToHandlers();

                return(Task.FromResult(0));
            }
コード例 #9
0
 public Task Handle(MyMessage message, IMessageHandlerContext context)
 {
     context.DoNotContinueDispatchingCurrentMessageToHandlers();
     return(Task.CompletedTask);
 }