public async Task <bool> RunAsync(AwardingScheduleArgs args) { IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>(); using (var uow = unitOfWorkManager.Begin()) { ILotteryCalculator lotteryCalculator = await _lotteryCalculatorFactory.GetLotteryCalculatorAsync(args.LdpOrderId); Handle handle = await lotteryCalculator.CalculateAsync(); _logger.LogInformation("Execute Awarding Scheduler: {0}-{1}-{2}", args.LdpMerchanerId, args.LdpOrderId, handle); uow.Complete(); switch (handle) { case Handle.Winner: await _dispatchQueryingMessageService.PublishAsync(args.LdpOrderId, args.LdpMerchanerId, args.LvpOrderId, args.LvpMerchanerId, args.LotteryId, QueryingTypes.Awarding); return(true); case Handle.Losing: await _lotteryNoticingMessagePublisher.PublishAsync($"LotteryOrdering.Awarded.{args.LvpMerchanerId}", new NoticeMessage <LotteryAwarded>(args.LdpOrderId, args.LdpMerchanerId, new LotteryAwarded { LvpOrderId = args.LvpOrderId, LvpMerchanerId = args.LvpMerchanerId, BonusAmount = 0, AftertaxBonusAmount = 0, AwardingType = LotteryAwardingTypes.Loseing, })); return(true); case Handle.Waiting: return(false); } return(false); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await _busClient.SubscribeAsync <OrderingDispatchMessage>(async (message) => { try { _logger.LogInformation("Received ordering message. LdpOrderId:{0} LvpMerchanerId:{1}", message.LdpOrderId, message.LdpMerchanerId); var handle = await _orderingDispatcher.DispatchAsync(message); switch (handle) { case AcceptedHandle accepted: { _logger.LogInformation($"Ordering Success: {message.LdpOrderId}-{message.LdpMerchanerId}-{message.LvpOrder.LvpOrderId}-{message.LvpOrder.LvpVenderId}-{message.LvpOrder.LotteryId}-{message.LvpOrder.LotteryPlayId}-{message.LvpOrder.InvestCode}"); await _dispatchQueryingMessageService.PublishAsync(message.LdpOrderId, message.LdpMerchanerId, message.LvpOrder.LvpOrderId, message.LvpOrder.LvpVenderId, message.LvpOrder.LotteryId, QueryingTypes.Ticketing); return(new Ack()); } case RejectedHandle rejected: { if (rejected.Reorder) { return(new Nack()); } _logger.LogInformation($"Ordering Rejected: {message.LdpMerchanerId}-{message.LvpOrder.LvpOrderId}-{message.LdpOrderId}"); await _lotteryNoticingMessagePublisher.PublishAsync($"LotteryOrdering.Ticketed.{message.LdpMerchanerId}", new NoticeMessage <LotteryTicketed>(message.LdpOrderId, message.LdpMerchanerId, new LotteryTicketed { LvpOrderId = message.LvpOrder.LvpOrderId, LvpMerchanerId = message.LvpOrder.LvpVenderId, TicketingType = LotteryTicketingTypes.Failure })); return(new Ack()); } } } catch (Exception ex) { _logger.LogError(ex, "Error of the ordering message processing. LdpOrderId:{0} LdpMerchanerId:{1}", message.LdpOrderId, message.LdpMerchanerId); } return(new Nack()); }, context => { context.UseSubscribeConfiguration(configuration => { configuration.OnDeclaredExchange(exchange => { exchange.WithName("Baibaocp.LotteryDispatching") .WithDurability(true) .WithAutoDelete(false) .WithType(ExchangeType.Topic); }); configuration.FromDeclaredQueue(queue => { queue.WithName($"LotteryDispatching.{_dispatcherConfiguration.MerchanterName}.Orders") .WithAutoDelete(false) .WithDurability(true); }); configuration.Consume(consume => { consume.WithRoutingKey($"LotteryDispatching.Ordering.{_dispatcherConfiguration.MerchanterId}"); }); }); }, stoppingToken); }