Пример #1
0
        public void Producer_WithExpectedParameters()
        {
            RabbitMQProducer producer = new RabbitMQProducer();
            string           message  = "Hello,World!";
            bool             success  = producer.Send(queue.Example01, message: message, durable: true, isPersistent: true);

            Assert.True(success);
        }
Пример #2
0
        public void TestIfWeReceiveTheMessageSent()
        {
            RabbitMQProducer rmp = new RabbitMQProducer("165.22.199.153", "admin", "2MmV2KjEhX36DaZeyAqhbifbp86YDxHG7yJq2R7JPJwJiXvN7jXpqhxjUr4ZCkGL");

            rmp.Send("test_queue", "testing");

            RabbitMQConsumer rmc = new RabbitMQConsumer("165.22.199.153", "admin", "2MmV2KjEhX36DaZeyAqhbifbp86YDxHG7yJq2R7JPJwJiXvN7jXpqhxjUr4ZCkGL");

            Assert.AreEqual("testing", rmc.Receive("test_queue"));
        }
        /// <summary>
        ///     发红包
        /// </summary>
        /// <returns></returns>
        public async Task <Tuple <bool, string, string> > SendRedEnvelopAsync()
        {
            try
            {
                // 发红包之前再验证下
                var validateResult = await ValidateAsync();

                if (!validateResult.Item1)
                {
                    return(validateResult);
                }

                // 怼到redis里面
                var cacheResult =
                    await _oaRedEnvelopeCacheManager.SaveUserOARedEnvelopeObjectAsync(_oaRedEnvelopeBuilderModel);

                // 判断是否异步
                using (var configClient = new Service.Config.ConfigClient())
                {
                    // 判断开关是否打开
                    var asyncFlag = configClient.GetOrSetRuntimeSwitch("OAEnvelopeAsyscFlag")?.Result?.Value ?? false;
                    // 判断是走同步还是异步
                    if (asyncFlag)
                    {
                        // 发送MQ
                        if (cacheResult)
                        {
                            // 成功
                            // 发送到MQ中
                            MqProducer.Send("notification.OAEnvelopeReciveConsumer", _oaRedEnvelopeBuilderModel, 1000);

                            return(await Task.FromResult(Tuple.Create(true, string.Empty, string.Empty)));
                        }
                    }
                    else
                    {
                        return(await CallbackRedEnvelopAsync());
                    }
                }
                // 失败
                return(Tuple.Create(false, "-3", ""));
            }
            catch (Exception e)
            {
                Logger.Error(
                    $"OARedEnvelopeUserReceiveManager -> SendRedEnvelopAsync -> {JsonConvert.SerializeObject(_oaRedEnvelopeBuilderModel)}",
                    e.InnerException ?? e);
                throw;
            }
        }
Пример #4
0
        public void Test_Write_With_Incorrect_Password()
        {
            RabbitMQProducer rmq = new RabbitMQProducer("165.22.199.153", "admin", "MmV2KjEhX36DaZeyAqhbifbp86YDxHG7yJq2R7JPJwJiXvN7jXpqhxjUr4ZCkGL");

            Assert.ThrowsException <RabbitMQ.Client.Exceptions.BrokerUnreachableException>(() => rmq.Send("Test_Queue", "Test"));
        }
Пример #5
0
        /// <summary>
        /// 问答抽奖
        /// </summary>
        /// <param name="userId">用户userId</param>
        /// <param name="deviceId">设备Id</param>
        /// <param name="Channal">渠道</param>
        /// <param name="hashKey">抽奖hashKey</param>
        /// <param name="phone">手机号</param>
        /// <param name="refer">url</param>
        /// <param name="grade">得分</param>
        /// <returns></returns>
        public async Task <OperationResult <BigBrandResponse> > GetAnswerPacketAsync(Guid userId, string deviceId, string Channal, string hashKey, string phone, string refer)
        {
            if (string.IsNullOrWhiteSpace(hashKey))
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "抽奖活动不存在"
                }));
            }

            Regex regex = new Regex("^([0-9]|[a-z]|[A-Z]){7}([0-9]|[a-z]|[A-Z])$");

            if (!regex.IsMatch(hashKey))
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "抽奖活动hashkey不匹配"
                }));
            }

            if (userId == null)
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "用户UserId不能为空"
                }));
            }

            BigBrandResponse result   = new BigBrandResponse();
            BigBrandLogic    bigBrand = new BigBrandLogic(hashKey, userId, phone, deviceId, Channal);

            bigBrand.Refer = refer;

            var isResult = await bigBrand.IsSelectCanPackage();

            if (!isResult.Result)
            {
                result.Code = 0;
                if (bigBrand.entity.BigBrandType == 2)
                {
                    result.Msg = "您的积分不足,无法抽奖哦";
                }
                else if (bigBrand.entity.BigBrandType == 3)
                {
                    result.Msg = "抱歉,只有指定用户才能参加此抽奖哦";
                }
                else
                {
                    result.Msg = "抽奖次数不足";
                }

                return(OperationResult.FromResult(result));
            }

            System.Diagnostics.Stopwatch watcher = new System.Diagnostics.Stopwatch();
            watcher.Restart();
            bigBrand._time = await QuesAnsManager.GetGrade(userId, hashKey);

            watcher.Stop();
            Logger.Info($"GetAnswerPacketAsync GetGrade times {watcher.ElapsedMilliseconds}");
            bigBrand._time += 1;
            watcher.Restart();
            var pageIndex = bigBrand.GetRandomPageckagePKID();

            watcher.Stop();
            Logger.Info($"GetAnswerPacketAsync GetRandomPageckagePKID times {watcher.ElapsedMilliseconds}");
            if (pageIndex <= 0)
            {
                result.Code = 0;
                result.Msg  = "对不起,您来晚了";
                return(OperationResult.FromResult(result));
            }
            watcher.Restart();
            var response = await bigBrand.CreatePageage(pageIndex);

            watcher.Stop();
            Logger.Info($"GetAnswerPacketAsync CreatePageage times {watcher.ElapsedMilliseconds}");
            if (!response.Success)
            {
                return(OperationResult.FromError <BigBrandResponse>(response.ErrorCode, response.ErrorMessage));
            }
            var page = response.Result;

            watcher.Restart();
            await bigBrand.AddPackageLog(page.PKID, page.PromotionCodePKIDs);

            watcher.Stop();
            Logger.Info($"GetAnswerPacketAsync AddPackageLog times {watcher.ElapsedMilliseconds}");
            bigBrand._time        -= 1;
            result.Code            = 1;
            result.PromptImg       = page.PromptImg;
            result.PromptMsg       = page.PromptMsg.Replace("{{allquestion}}", bigBrand?.entity?.AnsQuesConfig?.TipCount.ToString()).Replace("{{rightanswer}}", bigBrand?._time.ToString());
            result.PromptType      = page.PromptType;
            result.RedirectAPP     = page.RedirectAPP;
            result.RedirectBtnText = page.RedirectBtnText;
            result.RedirectH5      = page.RedirectH5;
            result.RedirectWXAPP   = page.RedirectWXAPP;
            result.RedirectHuaWei  = page.RedirectHuaWei;
            result.WxAppId         = page.WxAppId;
            result.RewardType      = page.RewardType;
            result.IsShare         = bigBrand.IsShare;
            result.TimeCount       = bigBrand.TimeCount;
            result.ShareTimes      = bigBrand.ShareTimes;
            result.Time            = bigBrand._time;
            result.RealTip         = bigBrand?.RealTip;
            if (GlobalConstant.HashKey_VehicleTypeCertificationRights.Contains(hashKey))
            {
                result.DefaultPool     = bigBrand.DefaultPool;
                result.CouponRuleItems = await bigBrand.GetCouponRuleItems(page.PKID, DateTime.Now);
            }
            produceer?.Send("notification.TaskActionQueue", new
            {
                UserId     = userId,
                ActionName = "2LuckyMoney",
                HashKey    = hashKey
            });
            return(OperationResult.FromResult(result));
        }