public void DefaultOptionsMatchDefaultDeconstruction() { (var defaultPartitionId, var defaultPartitionKey) = EnqueueEventOptions.DeconstructOrUseDefaultAttributes(); (var newPartitionId, var newPartitionKey) = new EnqueueEventOptions(); Assert.That(defaultPartitionId, Is.EqualTo(newPartitionId), "The partition identifier of the default attributes should match empty deconstruction."); Assert.That(defaultPartitionKey, Is.EqualTo(newPartitionKey), "The partition key of the default attributes should match empty deconstruction."); }
public async Task PartitionIdBuffered() { await using var scope = await EventHubScope.CreateAsync(1); #region Snippet:EventHubs_Sample04_PartitionIdBuffered #if SNIPPET var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>"; var eventHubName = "<< NAME OF THE EVENT HUB >>"; #else var connectionString = EventHubsTestEnvironment.Instance.EventHubsConnectionString; var eventHubName = scope.EventHubName; #endif var producer = new EventHubBufferedProducerClient(connectionString, eventHubName); // The failure handler is required and invoked after all allowable // retries were applied. producer.SendEventBatchFailedAsync += args => { Debug.WriteLine($"Publishing failed for { args.EventBatch.Count } events. Error: '{ args.Exception.Message }'"); return(Task.CompletedTask); }; // The success handler is optional. producer.SendEventBatchSucceededAsync += args => { Debug.WriteLine($"{ args.EventBatch.Count } events were published to partition: '{ args.PartitionId }."); return(Task.CompletedTask); }; try { string firstPartition = (await producer.GetPartitionIdsAsync()).First(); var enqueueOptions = new EnqueueEventOptions { PartitionId = firstPartition }; for (var index = 0; index < 5; ++index) { var eventData = new EventData($"Event #{ index }"); await producer.EnqueueEventAsync(eventData, enqueueOptions); } } finally { // Closing the producer will flush any // enqueued events that have not been published. await producer.CloseAsync(); } #endregion }
public void DeconstructOrUseDefaultAttributesUsesOptionsWhenProvided() { var options = new EnqueueEventOptions { PartitionId = "0", PartitionKey = "some_partition_123" }; (var partitionId, var partitionKey) = EnqueueEventOptions.DeconstructOrUseDefaultAttributes(options); Assert.That(partitionId, Is.EqualTo(options.PartitionId), "The partition identifier of the deconstruction should match."); Assert.That(partitionKey, Is.EqualTo(options.PartitionKey), "The partition key of the deconstruction should match."); }
public void OptionsCanBeDeconstructed() { var options = new EnqueueEventOptions { PartitionId = "0", PartitionKey = "some_partition_123" }; (var partitionId, var partitionKey) = options; Assert.That(partitionId, Is.EqualTo(options.PartitionId), "The partition identifier of the deconstruction should match."); Assert.That(partitionKey, Is.EqualTo(options.PartitionKey), "The partition key of the deconstruction should match."); }