Beispiel #1
0
        // Rename PollOnce ?

        public async Task <IReadOnlyList <IQueueMessage <string> > > PollAsync(int take, TimeSpan?lockTime, CancellationToken cancelationToken)
        {
            // Blocks until we recieve a message

            while (!cancelationToken.IsCancellationRequested)
            {
                var result = await client.ReceiveMessagesAsync(url, new RecieveMessagesRequest(take, lockTime, TimeSpan.FromSeconds(20))).ConfigureAwait(false);

                if (result.Length > 0)
                {
                    return(result);
                }
            }

            return(Array.Empty <IQueueMessage <string> >());
        }
Beispiel #2
0
        // TODO: Overload with serializer (Default to JSON)

        public async Task <IReadOnlyList <IQueueMessage <T> > > PollAsync(int take, TimeSpan?lockTime, CancellationToken cancelationToken)
        {
            // Blocks until we recieve a message

            while (!cancelationToken.IsCancellationRequested)
            {
                var result = await client.ReceiveMessagesAsync(url, new RecieveMessagesRequest(take, lockTime, TimeSpan.FromSeconds(20))).ConfigureAwait(false);

                if (result.Length == 0)
                {
                    continue;
                }

                return(result.Select(m => (IQueueMessage <T>) new JsonEncodedMessage <T>(m)).ToList());
            }

            return(new IQueueMessage <T> [0]);
        }
Beispiel #3
0
        // TODO: Overload with serializer (Default to JSON)

        public async Task <IReadOnlyList <IQueueMessage <T> > > PollAsync(
            int take,
            TimeSpan?lockTime,
            CancellationToken cancellationToken = default)
        {
            // Blocks until we recieve a message

            var request = new RecieveMessagesRequest(take, lockTime, waitTime: TimeSpan.FromSeconds(20));

            while (!cancellationToken.IsCancellationRequested)
            {
                var result = await client.ReceiveMessagesAsync(url, request).ConfigureAwait(false);

                if (result.Length == 0)
                {
                    continue;
                }

                return(Convert(result));
            }

            return(Array.Empty <IQueueMessage <T> >());
        }