Exemple #1
0
        public IEnumerable <EventData> Load(string partitionKey, int version)
        {
            var minRowKey = version.ToString("D10");
            var query     = GetEntitiesQuery(partitionKey, minRowKey, RowKeyVersionUpperLimit);
            // TODO: use async APIs, continuation tokens
            var all = eventStoreRetryPolicy.ExecuteAction(() => query.Execute());

            return(all.Select(x => Mapper.Map(x, new EventData {
                Version = int.Parse(x.RowKey)
            })));
        }
Exemple #2
0
        /// <summary>
        ///     Gets the pending events for publishing asynchronously using delegate continuations.
        /// </summary>
        /// <param name="partitionKey">The partition key to get events from.</param>
        /// <param name="successCallback">
        ///     The callback that will be called if the data is successfully retrieved.
        ///     The first argument of the callback is the list of pending events.
        ///     The second argument is true if there are more records that were not retrieved.
        /// </param>
        /// <param name="exceptionCallback">The callback used if there is an exception that does not allow to continue.</param>
        public void GetPendingAsync(string partitionKey, Action <IEnumerable <IEventRecord>, bool> successCallback, Action <Exception> exceptionCallback)
        {
            var query = GetEntitiesQuery(partitionKey, UnpublishedRowKeyPrefix, UnpublishedRowKeyPrefixUpperLimit);

            pendingEventsQueueRetryPolicy
            .ExecuteAction(
                ac => query.BeginExecuteSegmented(ac, null),
                ar => query.EndExecuteSegmented(ar),
                rs => {
                var all = rs.Results.ToList();
                successCallback(rs.Results, rs.HasMoreResults);
            },
                exceptionCallback);
        }
        public AzureMessageLogWriter(CloudStorageAccount account, string tableName)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException("tableName");
            }

            this.account            = account;
            this.tableName          = tableName;
            tableClient             = account.CreateCloudTableClient();
            tableClient.RetryPolicy = RetryPolicies.NoRetry();

            var retryStrategy = new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1));

            retryPolicy = new RetryPolicy <StorageTransientErrorDetectionStrategy>(retryStrategy);

            retryPolicy.ExecuteAction(() => tableClient.CreateTableIfNotExist(tableName));
        }
Exemple #4
0
        public EventStore(CloudStorageAccount account, string tableName)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException("tableName");
            }

            this.account            = account;
            this.tableName          = tableName;
            tableClient             = account.CreateCloudTableClient();
            tableClient.RetryPolicy = RetryPolicies.NoRetry();

            // TODO: This could be injected.
            var backgroundRetryStrategy = new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1));
            var blockingRetryStrategy   = new Incremental(3, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));

            pendingEventsQueueRetryPolicy           = new RetryPolicy <StorageTransientErrorDetectionStrategy>(backgroundRetryStrategy);
            pendingEventsQueueRetryPolicy.Retrying += (s, e) => {
                var handler = Retrying;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }

                Trace.TraceWarning("An error occurred in attempt number {1} to access table storage (PendingEventsQueue): {0}", e.LastException.Message, e.CurrentRetryCount);
            };
            eventStoreRetryPolicy           = new RetryPolicy <StorageTransientErrorDetectionStrategy>(blockingRetryStrategy);
            eventStoreRetryPolicy.Retrying += (s, e) => Trace.TraceWarning(
                "An error occurred in attempt number {1} to access table storage (EventStore): {0}",
                e.LastException.Message,
                e.CurrentRetryCount);

            eventStoreRetryPolicy.ExecuteAction(() => tableClient.CreateTableIfNotExist(tableName));
        }
        public void Save(MessageLogEntity entity)
        {
            retryPolicy.ExecuteAction(() => {
                var context = tableClient.GetDataServiceContext();

                context.AddObject(tableName, entity);

                try {
                    context.SaveChanges();
                } catch (DataServiceRequestException dsre) {
                    var clientException = dsre.InnerException as DataServiceClientException;
                    // If we get a conflict, we ignore it as we've already saved the message,
                    // making this log idempotent.
                    if (clientException == null || clientException.StatusCode != (int)HttpStatusCode.Conflict)
                    {
                        throw;
                    }
                }
            });
        }