예제 #1
0
        public async Task <IReadOnlyList <IQueueMessage <T> > > GetAsync(int take, TimeSpan?lockTime)
        {
            var request = new RecieveMessagesRequest(take, lockTime);

            return((await client.ReceiveMessagesAsync(url, request).ConfigureAwait(false))
                   .Select(m => (IQueueMessage <T>) new JsonEncodedMessage <T>(m))
                   .ToList());
        }
예제 #2
0
        public async Task <IReadOnlyList <IQueueMessage <T> > > GetAsync(int take, TimeSpan?lockTime)
        {
            var request = new RecieveMessagesRequest(take, lockTime);

            var result = await client.ReceiveMessagesAsync(url, request).ConfigureAwait(false);

            return(Convert(result));
        }
예제 #3
0
        public async Task <SqsMessage[]> ReceiveMessagesAsync(Uri queueUrl, RecieveMessagesRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var httpRequest = new HttpRequestMessage(HttpMethod.Post, queueUrl)
            {
                Content = GetPostContent(request.ToParams())
            };

            string responseText = await SendAsync(httpRequest).ConfigureAwait(false);

            var response = ReceiveMessageResponse.Parse(responseText);

            return(response.ReceiveMessageResult.Items ?? Array.Empty <SqsMessage>());
        }
예제 #4
0
        public async Task <SqsMessage[]> ReceiveMessagesAsync(Uri queueUrl, RecieveMessagesRequest request)
        {
            #region Preconditions

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            #endregion

            var httpRequest = new HttpRequestMessage(HttpMethod.Post, queueUrl)
            {
                Content = GetPostContent(request.ToParams())
            };

            var responseText = await SendAsync(httpRequest).ConfigureAwait(false);

            return(RecieveMessageResponse.Parse(responseText).ToArray());
        }
예제 #5
0
        public async Task <IReadOnlyList <IQueueMessage <string> > > PollAsync(
            int take,
            TimeSpan?lockTime,
            CancellationToken cancellationToken = default)
        {
            // Blocks until we recieve a message

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

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

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

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