Пример #1
0
        /// <summary>
        /// Registers the given <paramref name="subscriberAddress"/> as a subscriber of the topic named <paramref name="topic"/>
        /// by inserting a row with the address as the row ID under a partition key named after the topic
        /// </summary>
        public async Task RegisterSubscriber(string topic, string subscriberAddress)
        {
            try
            {
                var entity              = new AzureStorageSubscription(topic, subscriberAddress);
                var table               = GetTable();
                var operationContext    = new OperationContext();
                var tableRequestOptions = new TableRequestOptions {
                    RetryPolicy = new ExponentialRetry()
                };
                var result = await table.ExecuteAsync(TableOperation.InsertOrReplace(entity), tableRequestOptions, operationContext);

                if (result.HttpStatusCode >= 200 && result.HttpStatusCode < 300)
                {
                    return;
                }

                throw new RebusApplicationException(
                          $"HTTP status {result.HttpStatusCode} returned when registering '{subscriberAddress}' as a subscriber for '{topic}'");
            }
            catch (Exception exception)
            {
                throw new RebusApplicationException(exception, $"Could not subscribe {subscriberAddress} to '{topic}'");
            }
        }
Пример #2
0
 /// <summary>
 /// Unregisters the given <paramref name="subscriberAddress"/> as a subscriber of the topic named <paramref name="topic"/>
 /// by removing the row with the address as the row ID under a partition key named after the topic
 /// </summary>
 public async Task UnregisterSubscriber(string topic, string subscriberAddress)
 {
     try
     {
         var entity = new AzureStorageSubscription(topic, subscriberAddress)
         {
             ETag = "*"
         };
         var tableReference   = GetTable();
         var operationContext = new OperationContext();
         var result           = await tableReference.ExecuteAsync(TableOperation.Delete(entity), new TableRequestOptions { RetryPolicy = new ExponentialRetry() }, operationContext);
     }
     catch (Exception exception)
     {
         throw new RebusApplicationException(exception, $"Could not unsubscribe {subscriberAddress} from '{topic}'");
     }
 }
 /// <summary>
 /// Registers the given <paramref name="subscriberAddress"/> as a subscriber of the topic named <paramref name="topic"/>
 /// by inserting a row with the address as the row ID under a partition key named after the topic
 /// </summary>
 public async Task RegisterSubscriber(string topic, string subscriberAddress)
 {
     try
     {
         var entity              = new AzureStorageSubscription(topic, subscriberAddress);
         var table               = GetTable();
         var operationContext    = new OperationContext();
         var tableRequestOptions = new TableRequestOptions {
             RetryPolicy = new ExponentialRetry()
         };
         var result = await table.ExecuteAsync(TableOperation.InsertOrReplace(entity), tableRequestOptions, operationContext);
     }
     catch (Exception exception)
     {
         throw new RebusApplicationException(exception, $"Could not subscribe {subscriberAddress} to '{topic}'");
     }
 }