Beispiel #1
0
 public LiangcaiReceivingMiddleware(RequestDelegate next, ILogger <LiangcaiReceivingMiddleware> logger, ILotteryNoticingMessagePublisher lotteryNoticingMessagePublisher, IOrderingApplicationService orderingApplicationService, ILotteryMerchanterApplicationService lotteryMerchanterApplicationService)
 {
     _next   = next;
     _logger = logger;
     _lotteryNoticingMessagePublisher     = lotteryNoticingMessagePublisher;
     _orderingApplicationService          = orderingApplicationService;
     _lotteryMerchanterApplicationService = lotteryMerchanterApplicationService;
 }
Beispiel #2
0
 public SuicaiNoticing(RequestDelegate next, ILogger <SuicaiNoticing> logger, ILotteryNoticingMessagePublisher lotteryNoticingMessagePublisher, IOrderingApplicationService orderingApplicationService, ILotteryMerchanterApplicationService lotteryMerchanterApplicationService)
 {
     _next   = next;
     _logger = logger;
     _lotteryNoticingMessagePublisher     = lotteryNoticingMessagePublisher;
     _orderingApplicationService          = orderingApplicationService;
     _lotteryMerchanterApplicationService = lotteryMerchanterApplicationService;
     _crypter = Tripledescrypt.Create(CipherMode.CBC, PaddingMode.PKCS7);
 }
 protected override Task ExecuteAsync(CancellationToken stoppingToken)
 {
     return(_busClient.SubscribeAsync <NoticeMessage <LotteryTicketed> >(async(message) =>
     {
         try
         {
             if (message.Content.TicketingType == LotteryTicketingTypes.Success)
             {
                 IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>();
                 using (var uow = unitOfWorkManager.Begin())
                 {
                     IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
                     var order = await orderingApplicationService.FindOrderAsync(message.LdpOrderId);
                     if (order == null)
                     {
                         return new Ack();
                     }
                     ILotteryMerchanterApplicationService lotteryMerchanterApplicationService = _iocResolver.GetRequiredService <ILotteryMerchanterApplicationService>();
                     await lotteryMerchanterApplicationService.Ticketing(message.LdpMerchanerId, order.Id, order.LotteryId, order.InvestAmount);
                     await lotteryMerchanterApplicationService.Ticketing(order.LvpVenderId, order.Id, order.LotteryId, order.InvestAmount);
                     uow.Complete();
                 }
             }
             _logger.LogInformation("Received ticketing message: {1} {0}", message.LdpMerchanerId, message.LdpOrderId);
             return new Ack();
         }
         catch (Exception ex)
         {
             _logger.LogError(ex, "Received ticketing message: {1} {0}", message.LdpMerchanerId, message.LdpOrderId);
         }
         return new Nack();
     }, context =>
     {
         context.UseSubscribeConfiguration(configuration =>
         {
             configuration.OnDeclaredExchange(exchange =>
             {
                 exchange.WithName("Baibaocp.LotteryNoticing")
                 .WithDurability(true)
                 .WithAutoDelete(false)
                 .WithType(ExchangeType.Topic);
             });
             configuration.FromDeclaredQueue(queue =>
             {
                 queue.WithName("LotteryTrading.TradeLogging.Tickets")
                 .WithAutoDelete(false)
                 .WithDurability(true);
             });
             configuration.Consume(consume =>
             {
                 consume.WithRoutingKey("LotteryOrdering.Ticketed.#");
             });
         });
     }, stoppingToken));
 }
Beispiel #4
0
        public AwardingNotifier(INoticeSerializer serializer, ILotteryMerchanterApplicationService lotteryMerchanterApplicationService, ILogger <AwardingNotifier> logger)
        {
            _serializer = serializer;
            _logger     = logger;
            _lotteryMerchanterApplicationService = lotteryMerchanterApplicationService;
            _client = new HttpClient();

            _policy = Policy.Handle <Exception>().OrResult(false).WaitAndRetryAsync(2, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
            {
                _logger.LogWarning("推送失败:{0} {1} 重试中...", ex.Result, ex.Exception?.Message);
            });
        }
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            return(_busClient.SubscribeAsync <LvpOrderMessage>(async(message) =>
            {
                try
                {
                    ILotteryMerchanterApplicationService lotteryMerchanterApplicationService = _iocResolver.GetRequiredService <ILotteryMerchanterApplicationService>();

                    IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>();
                    using (var uow = unitOfWorkManager.Begin())
                    {
                        /* 此处必须保证投注渠道已经开通相应的彩种和出票渠道*/
                        string ldpVenderId = await lotteryMerchanterApplicationService.FindLdpMerchanterIdAsync(message.LvpVenderId, message.LotteryId);
                        if (string.IsNullOrEmpty(ldpVenderId))
                        {
                            _logger.LogError("当前投注渠道{0}不支持该彩种{1}", message.LvpVenderId, message.LotteryId);
                            return new Nack();
                        }
                        IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
                        (LotteryMerchanteOrder order, TimeSpan? delay) = await orderingApplicationService.CreateAsync(message.LvpOrderId, message.LvpUserId, message.LvpVenderId, message.LotteryId, message.LotteryPlayId, message.IssueNumber, message.InvestCode, message.InvestType, message.InvestCount, message.InvestTimes, message.InvestAmount);

                        /* 需要延期投注的票加入计划任务,否则直接分票投注*/
                        if (delay.HasValue)
                        {
                            ISchedulerManager schedulerManager = _iocResolver.GetRequiredService <ISchedulerManager>();
                            await schedulerManager.EnqueueAsync <ILotteryOrderingScheduler, OrderingScheduleArgs>(new OrderingScheduleArgs
                            {
                                LdpOrderId = order.Id,
                                LdpMerchanerId = ldpVenderId,
                                Message = message
                            }, SchedulerPriority.High, delay);
                        }
                        else
                        {
                            await _dispatchOrderingMessageService.PublishAsync(order.Id, ldpVenderId, message);
                        }
                        uow.Complete();
                        return new Ack();
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error of the ordering :{0}", message.LvpOrderId);
                }
                return new Nack();
            }, context =>
            {
                context.UseSubscribeConfiguration(configuration =>
                {
                    configuration.OnDeclaredExchange(exchange =>
                    {
                        exchange.WithName("Baibaocp.LotteryOrdering")
                        .WithDurability(true)
                        .WithAutoDelete(false)
                        .WithType(ExchangeType.Topic);
                    });
                    configuration.FromDeclaredQueue(queue =>
                    {
                        queue.WithName("LotteryOrdering.Orders")
                        .WithAutoDelete(false)
                        .WithDurability(true);
                    });
                    configuration.Consume(consume =>
                    {
                        consume.WithRoutingKey("LotteryOrdering.Accepted.#");
#if DEBUG
                        consume.WithPrefetchCount(1);
#endif
                    });
                });
            }, stoppingToken));
        }