コード例 #1
0
        /// <summary>
        /// Pulls the messaged from pub sub.
        /// </summary>
        /// <param name="ct">The ct.</param>
        protected static async Task <bool> PullMessagedFromPubSubAsync(CancellationToken ct)
        {
            bool bStatus = true;

            FirebaseTestSender.Init();
            var       firebasenet = new FirebaseTestSender();
            Stopwatch stopWatch   = new Stopwatch();

            long length = 0;

            lock (_redisOperationLock){
                length = _redisDB.ListLength(PendingQueue);
            }
            long       numOfMsg = length - 1;
            RedisValue message  = new RedisValue();
            FCMClient  client   = new FCMClient(serverKey);

            while (length > 0)
            {
                lock (_redisOperationLock){
                    length = _redisDB.ListLength(PendingQueue);

                    if (length >= 1)
                    {
                        message = _redisDB.ListRightPop(PendingQueue);
                    }
                }
                if (length >= 1)
                {
                    Dictionary <String, String> convertedMessage = null;
                    String[] recievedRegistration_ids;
                    bool     converted = ConvertMessageWithTokens(message, out convertedMessage, out recievedRegistration_ids);

                    firebasenet.SenderDataPayloadToFirebaseAsync(convertedMessage, recievedRegistration_ids, client);
                }

                lock (_redisOperationLock){
                    length = _redisDB.ListLength(PendingQueue);
                }
            }

            while (true)
            {
                bool isFinished = CheckMessagesStatus();
                if (isFinished)
                {
                    break;
                }
                Thread.Sleep(50);
            }


            return(bStatus);
        }
コード例 #2
0
        /// <summary>
        /// Pulls the messaged from pub sub.
        /// </summary>
        /// <param name="ct">The ct.</param>
        protected static async Task <bool> PullMultiMessagedAsync(CancellationToken ct)
        {
            bool bStatus = true;

            FirebaseTestSender.Init();
            FCMClient client    = new FCMClient(serverKey);
            Stopwatch stopWatch = new Stopwatch();

            long length = 0;

            lock (_redisOperationLock){
                length = _redisDB.ListLength(PendingQueue);
            }
            long       numOfMsg = length - 1;
            RedisValue message  = new RedisValue();
            //RedisValue[] msgCollection = new RedisValue[1];
            long start = 0, end = 0;
            long step = length / 5;


            var msgCollection1 = _redisDB.ListRange(PendingQueue, 0, 999);
            var msgCollection2 = _redisDB.ListRange(PendingQueue, 1000, 1999);
            var msgCollection3 = _redisDB.ListRange(PendingQueue, 2000, 2999);
            var msgCollection4 = _redisDB.ListRange(PendingQueue, 3000, 3999);
            var msgCollection5 = _redisDB.ListRange(PendingQueue, 4000, 5000);

            _redisDB.ListTrimAsync(PendingQueue, 0, 0, CommandFlags.HighPriority);
            _redisDB.ListRightPopAsync(PendingQueue);

            Parallel.Invoke(() => DoSomeWork(msgCollection1, client), () => DoSomeWork(msgCollection2, client)
                            , () => DoSomeWork(msgCollection3, client), () => DoSomeWork(msgCollection4, client), () => DoSomeWork(msgCollection5, client));


            lock (_redisOperationLock){
                length = _redisDB.ListLength(PendingQueue);
            }



            while (true)
            {
                bool isFinished = CheckMessagesStatus();
                if (isFinished)
                {
                    break;
                }
                Thread.Sleep(50);
            }


            return(bStatus);
        }
コード例 #3
0
        private static void DoSomeWork(RedisValue[] msgCollection, FCMClient client)
        {
            var firebasenet = new FirebaseTestSender();

            foreach (var m in msgCollection)
            {
                Dictionary <String, String> convertedMessage = null;
                String[] recievedRegistration_ids;
                bool     converted = ConvertMessageWithTokens(m, out convertedMessage, out recievedRegistration_ids);
                firebasenet.SenderDataPayloadToFirebaseAsync(convertedMessage, recievedRegistration_ids, client);
            }
            ;
        }