Пример #1
0
        /// <summary>
        /// Delete an item from the queue.
        /// </summary>
        /// <param name="key">PopReceipt key.</param>
        /// <param name="cancellationToken">CancellationToken instance.</param>
        /// <returns>QueueItem&lt;TItem&gt; instance.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
        /// <exception cref="ArgumentException">All of the PopReceit instances in <paramref name="key"/> must reside within the same partition.</exception>
        public async Task <QueueItem <TItem> > DeleteItemAsync(PopReceipt key, CancellationToken cancellationToken)
        {
            QueueItem <TItem> item = default(QueueItem <TItem>);

            // Build the Uri and query parameters.
            string activityId  = Guid.NewGuid().ToString();
            string relativeUri = $"/api/{key}?requestid={activityId}";

            // Get the Resolved ServicePartition for the specified partition.
            ResolvedServicePartition rsp = await GetRspAsync(key.Partition, cancellationToken).ConfigureAwait(false);

            // Make the DELETE request to the service. CallAsync handles retries and moving endpoints.
            item = await CallAsync(rsp, cancellationToken, async (serviceEndpoints, ct) =>
            {
                string uri = serviceEndpoints.GetFirstEndpoint() + relativeUri;
                using (HttpResponseMessage result = await _http.DeleteAsync(uri, cancellationToken).ConfigureAwait(false))
                {
                    if (result.IsSuccessStatusCode)
                    {
                        return(result.GetResult <QueueItem <TItem> >());
                    }

                    // TODO: Replace with specific exception rather than this one.
                    throw new HttpRequestException(result.ReasonPhrase, new WebException(result.ReasonPhrase, WebExceptionStatus.ConnectFailure));
                }
            });

            // Return the item.
            return(item);
        }
Пример #2
0
 /// <summary>
 /// QueueItem constructor creating an leased or un-leased QueueItem with the passed expiration and enqueue time.
 /// </summary>
 /// <param name="key">PopReceipt containing the unique key for the item while in the queue.</param>
 /// <param name="queue">Destination queue of the item.</param>
 /// <param name="item">Item instance.</param>
 /// <param name="lease">Duration of the lease.</param>
 /// <param name="leaseUntil">Date and time the lease will expire.</param>
 /// <param name="expiresAt">Date and time the item expires.</param>
 /// <param name="enqueueTime">Date and time this item was first enqueued.</param>
 /// <param name="count">Number of times this item has been previously dequeued.</param>
 public QueueItem(PopReceipt key, int queue, TItem item, TimeSpan lease, DateTimeOffset leaseUntil, DateTimeOffset expiresAt, DateTimeOffset enqueueTime, int count)
 {
     Key            = key;
     Queue          = queue;
     Item           = item;
     EnqueueTime    = enqueueTime;
     LeasedUntil    = leaseUntil;
     LeaseDuration  = lease;
     ExpirationTime = expiresAt;
     DequeueCount   = count;
 }