public async Task ConfigureCustomEndpointAddress() { #region Snippet:EventHubs_Sample02_ConnectionOptionsCustomEndpoint #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 = "fake"; #endif var producerOptions = new EventHubProducerClientOptions(); producerOptions.ConnectionOptions.CustomEndpointAddress = new Uri("amqps://app-gateway.mycompany.com"); var producer = new EventHubProducerClient( connectionString, eventHubName, producerOptions); #endregion using var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); await producer.CloseAsync(cancellationSource.Token).IgnoreExceptions(); }
public async Task ConfigureProducerTransportByProperty() { #region Snippet:EventHubs_Sample02_ProducerTransportProperty var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>"; var eventHubName = "<< NAME OF THE EVENT HUB >>"; /*@@*/ /*@@*/ connectionString = EventHubsTestEnvironment.Instance.EventHubsConnectionString; /*@@*/ eventHubName = _scope.EventHubName; var producerOptions = new EventHubProducerClientOptions(); producerOptions.ConnectionOptions.TransportType = EventHubsTransportType.AmqpWebSockets; var producer = new EventHubProducerClient( connectionString, eventHubName, producerOptions); #endregion using var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); await producer.CloseAsync(cancellationSource.Token).IgnoreExceptions(); }
public async Task ConfigureProducerTransportWithFullOptions() { #region Snippet:EventHubs_Sample02_ProducerTransportFullConnectionOptions #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 = "fake"; #endif var producerOptions = new EventHubProducerClientOptions { ConnectionOptions = new EventHubConnectionOptions { TransportType = EventHubsTransportType.AmqpWebSockets } }; var producer = new EventHubProducerClient( connectionString, eventHubName, producerOptions); #endregion using var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); await producer.CloseAsync(cancellationSource.Token).IgnoreExceptions(); }
public void RespectsConnectionOptionsForProducer(string expectedPathName, string connectionString) { var testEndpoint = new Uri("http://mycustomendpoint.com"); EventHubOptions options = new EventHubOptions { CustomEndpointAddress = testEndpoint, ClientRetryOptions = new EventHubsRetryOptions { MaximumRetries = 10 } }; var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString)); var factory = ConfigurationUtilities.CreateFactory(configuration, options); var producer = factory.GetEventHubProducerClient(expectedPathName, "connection"); EventHubConnection connection = (EventHubConnection)typeof(EventHubProducerClient).GetProperty("Connection", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(producer); EventHubConnectionOptions connectionOptions = (EventHubConnectionOptions)typeof(EventHubConnection).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(connection); Assert.AreEqual(testEndpoint, connectionOptions.CustomEndpointAddress); Assert.AreEqual(expectedPathName, producer.EventHubName); EventHubProducerClientOptions producerOptions = (EventHubProducerClientOptions)typeof(EventHubProducerClient).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(producer); Assert.AreEqual(10, producerOptions.RetryOptions.MaximumRetries); Assert.AreEqual(expectedPathName, producer.EventHubName); }
public async Task ProducerManagesConcurrencyWhenPublishingEvents() { await using (EventHubScope scope = await EventHubScope.CreateAsync(1)) { var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); var options = new EventHubProducerClientOptions { EnableIdempotentPartitions = true }; await using var producer = new EventHubProducerClient(connectionString, options); var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); var partition = (await producer.GetPartitionIdsAsync(cancellationSource.Token)).First(); var sendOptions = new SendEventOptions { PartitionId = partition }; async Task sendEvents(int delayMilliseconds) { await Task.Delay(delayMilliseconds); await producer.SendAsync(EventGenerator.CreateEvents(2), sendOptions, cancellationSource.Token); } var pendingSends = Task.WhenAll( sendEvents(100), sendEvents(50), sendEvents(0) ); Assert.That(async() => await pendingSends, Throws.Nothing); } }
public void RespectsConnectionOptionsForProducer(string expectedPathName, string connectionString) { var testEndpoint = new Uri("http://mycustomendpoint.com"); EventHubOptions options = new EventHubOptions { CustomEndpointAddress = testEndpoint, ClientRetryOptions = new EventHubsRetryOptions { MaximumRetries = 10 } }; var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString)); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration), new AzureEventSourceLogForwarder(new NullLoggerFactory())); var producer = factory.GetEventHubProducerClient(expectedPathName, "connection"); EventHubConnection connection = (EventHubConnection)typeof(EventHubProducerClient).GetProperty("Connection", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(producer); EventHubConnectionOptions connectionOptions = (EventHubConnectionOptions)typeof(EventHubConnection).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(connection); Assert.AreEqual(testEndpoint, connectionOptions.CustomEndpointAddress); Assert.AreEqual(expectedPathName, producer.EventHubName); EventHubProducerClientOptions producerOptions = (EventHubProducerClientOptions)typeof(EventHubProducerClient).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(producer); Assert.AreEqual(10, producerOptions.RetryOptions.MaximumRetries); Assert.AreEqual(expectedPathName, producer.EventHubName); }
public async Task ProducerCanPublishBatches(EventHubsTransportType transportType) { await using (EventHubScope scope = await EventHubScope.CreateAsync(1)) { var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); var options = new EventHubProducerClientOptions { EnableIdempotentPartitions = true, ConnectionOptions = new EventHubConnectionOptions { TransportType = transportType } }; await using var producer = new EventHubProducerClient(connectionString, options); var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); var partition = (await producer.GetPartitionIdsAsync()).First(); var batchOptions = new CreateBatchOptions { PartitionId = partition }; using var firstBatch = await producer.CreateBatchAsync(batchOptions, cancellationSource.Token); firstBatch.TryAdd(EventGenerator.CreateEvents(1).First()); using var secondBatch = await producer.CreateBatchAsync(batchOptions, cancellationSource.Token); secondBatch.TryAdd(EventGenerator.CreateEvents(1).First()); secondBatch.TryAdd(EventGenerator.CreateEvents(1).First()); Assert.That(async() => await producer.SendAsync(firstBatch, cancellationSource.Token), Throws.Nothing, "The first publishing operation was not successful."); Assert.That(async() => await producer.SendAsync(secondBatch, cancellationSource.Token), Throws.Nothing, "The second publishing operation was not successful."); } }
public async Task ProducerAllowsPublishingConcurrentlyToDifferentPartitions() { await using (EventHubScope scope = await EventHubScope.CreateAsync(4)) { var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); var options = new EventHubProducerClientOptions { EnableIdempotentPartitions = true }; await using var producer = new EventHubProducerClient(connectionString, options); var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); async Task sendEvents(string partition, int delayMilliseconds) { await Task.Delay(delayMilliseconds); await producer.SendAsync(EventGenerator.CreateEvents(5), new SendEventOptions { PartitionId = partition }, cancellationSource.Token); } var partitions = await producer.GetPartitionIdsAsync(cancellationSource.Token); var pendingSends = new List <Task>(); foreach (var partition in partitions) { pendingSends.Add(sendEvents(partition, 50)); pendingSends.Add(sendEvents(partition, 0)); } Assert.That(async() => await Task.WhenAll(pendingSends), Throws.Nothing); } }
public async Task ProducerUpdatesPropertiesAfterPublishingEvents() { await using (EventHubScope scope = await EventHubScope.CreateAsync(1)) { var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); var options = new EventHubProducerClientOptions { EnableIdempotentPartitions = true }; await using var producer = new EventHubProducerClient(connectionString, options); var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); var partition = (await producer.GetPartitionIdsAsync(cancellationSource.Token)).First(); var initialPartitionProperties = await producer.GetPartitionPublishingPropertiesAsync(partition); var sendOptions = new SendEventOptions { PartitionId = partition }; var events = EventGenerator.CreateEvents(10).ToArray(); await producer.SendAsync(events, sendOptions, cancellationSource.Token); var updatedPartitionProperties = await producer.GetPartitionPublishingPropertiesAsync(partition); Assert.That(updatedPartitionProperties.IsIdempotentPublishingEnabled, Is.True, "Idempotent publishing should be enabled."); Assert.That(updatedPartitionProperties.ProducerGroupId, Is.EqualTo(initialPartitionProperties.ProducerGroupId), "The producer group identifier should not have changed."); Assert.That(updatedPartitionProperties.OwnerLevel, Is.EqualTo(initialPartitionProperties.OwnerLevel), "The owner level should not have changed."); Assert.That(updatedPartitionProperties.LastPublishedSequenceNumber, Is.GreaterThan(initialPartitionProperties.LastPublishedSequenceNumber), "The last published sequence number should have increased."); } }
public async Task ConfigureProducerProxyWithFullOptions() { await using var scope = await EventHubScope.CreateAsync(1); #region Snippet:EventHubs_Sample02_ProducerProxyFullConnectionOptions var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>"; var eventHubName = "<< NAME OF THE EVENT HUB >>"; /*@@*/ /*@@*/ connectionString = EventHubsTestEnvironment.Instance.EventHubsConnectionString; /*@@*/ eventHubName = scope.EventHubName; var producerOptions = new EventHubProducerClientOptions { ConnectionOptions = new EventHubConnectionOptions { TransportType = EventHubsTransportType.AmqpWebSockets, Proxy = new WebProxy("https://proxyserver:80", true) } }; var producer = new EventHubProducerClient( connectionString, eventHubName, producerOptions); #endregion using var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); await producer.CloseAsync(cancellationSource.Token).IgnoreExceptions(); }
public void CreateFeatureFlagsDetectsWhenNoFeaturesWereRequested() { var options = new EventHubProducerClientOptions { EnableIdempotentPartitions = false }; Assert.That(options.CreateFeatureFlags(), Is.EqualTo(TransportProducerFeatures.None)); }
public void CreateFeatureFlagsDetectsIdempotentPublishing() { var options = new EventHubProducerClientOptions { EnableIdempotentPartitions = true }; Assert.That(options.CreateFeatureFlags(), Is.EqualTo(TransportProducerFeatures.IdempotentPublishing)); }
public async Task MakeConnection() { // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(this.options.Path); if (attr.HasFlag(FileAttributes.Directory)) { continuous = true; } else { continuous = false; } Console.WriteLine("Found Path."); // check if Connection string is good var builder = new Microsoft.Azure.EventHubs.EventHubsConnectionStringBuilder(this.options.ConnectionString); Uri endpointAddress = builder.Endpoint; // check for connection, using legacy EventHubs Microsoft.Azure.EventHubs.EventHubClient.CreateWithManagedServiceIdentity(endpointAddress, this.options.HubName); // Create a producer client that you can use to send events to an event hub var clientOptions = new EventHubProducerClientOptions(); clientOptions.ConnectionOptions.TransportType = EventHubsTransportType.AmqpWebSockets; this.producerClient = new EventHubProducerClient(this.options.ConnectionString, this.options.HubName, clientOptions); Console.WriteLine("Made Connection"); if (continuous) // add all files already present to be sent { //foreach (string f in Directory.GetFiles(this.options.Path, "*.json")) //{ // AllFiles.Add(f); //} } else { using EventDataBatch eventBatch = await producerClient.CreateBatchAsync(); var reader = new StreamReader(this.options.Path); var myJson = reader.ReadToEnd(); reader.Close(); Console.WriteLine("Read File."); //create and send event eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes(myJson))); this.bytesSent = eventBatch.SizeInBytes; await this.producerClient.SendAsync(eventBatch); Console.WriteLine($"Sent {this.options.Path}"); File.Delete(this.options.Path); Environment.Exit(1); } }
public void ConnectionStringConstructorSetsTheRetryPolicy() { var expected = Mock.Of<EventHubsRetryPolicy>(); var options = new EventHubProducerClientOptions { RetryOptions = new RetryOptions { CustomRetryPolicy = expected } }; var connectionString = "Endpoint=sb://somehost.com;SharedAccessKeyName=ABC;SharedAccessKey=123;EntityPath=somehub"; var producer = new EventHubProducerClient(connectionString, options); Assert.That(GetRetryPolicy(producer), Is.SameAs(expected)); }
public void ExpandedConstructorSetsTheRetryPolicy() { var expected = Mock.Of<EventHubsRetryPolicy>(); var credential = new Mock<EventHubTokenCredential>(Mock.Of<TokenCredential>(), "{namespace}.servicebus.windows.net"); var options = new EventHubProducerClientOptions { RetryOptions = new RetryOptions { CustomRetryPolicy = expected } }; var producer = new EventHubProducerClient("namespace", "eventHub", credential.Object, options); Assert.That(GetRetryPolicy(producer), Is.SameAs(expected)); }
public void ConnectionConstructorSetsTheRetryPolicy() { var expected = Mock.Of<EventHubsRetryPolicy>(); var options = new EventHubProducerClientOptions { RetryOptions = new RetryOptions { CustomRetryPolicy = expected } }; var mockConnection = new MockConnection(); var producer = new EventHubProducerClient(mockConnection, options); Assert.That(GetRetryPolicy(producer), Is.SameAs(expected)); }
/// <summary> /// Runs the sample using the specified Event Hubs connection information. /// </summary> /// /// <param name="connectionString">The connection string for the Event Hubs namespace that the sample should target.</param> /// <param name="eventHubName">The name of the Event Hub, sometimes known as its path, that she sample should run against.</param> /// public async Task RunAsync(string connectionString, string eventHubName) { // The clients for an Event Hub client each offer additional options on creation, allowing you to control different aspects of its behavior // should your scenario have needs that differ from the common defaults. If you choose not to provide these options, the default behaviors // suitable to most scenarios are used. // // Each different Event Hub client allows you to customize how it interacts with the Event Hubs service, such as by customizing how it connects // to the service by specifying the transport that communication should use and whether a proxy should be used for network communications. Please // note that a proxy is only supported when using WebSockets as a transport; it isn't compatible with raw TCP or other transport channels. // // The Event Hub clients each offer a common set of options, such as specifying the timeout and retry approach used while interacting with the // Event Hubs service. A specific client will potentially allow you to customize behavior specific to its related operations. // // This sample will customize the transport for the connection, using WebSockets and will adjust some of the retry-related values for // illustration. var producerOptions = new EventHubProducerClientOptions { ConnectionOptions = new EventHubConnectionOptions { TransportType = EventHubsTransportType.AmqpWebSockets, Proxy = (IWebProxy)null }, RetryOptions = new EventHubsRetryOptions { MaximumRetries = 5, TryTimeout = TimeSpan.FromMinutes(1) } }; await using (var producer = new EventHubProducerClient(connectionString, eventHubName, producerOptions)) { // Using the client, we will inspect the Event Hub that it is connected to, getting // access to metadata about it. EventHubProperties properties = await producer.GetEventHubPropertiesAsync(); Console.WriteLine("The Event Hub has the following properties:"); Console.WriteLine($"\tThe path to the Event Hub from the namespace is: { properties.Name }"); Console.WriteLine($"\tThe Event Hub was created at: { properties.CreatedOn.ToString("yyyy-MM-dd hh:mm:ss tt (zzz)") }, in UTC."); Console.WriteLine("\tThe Event Hub has the following partitions:"); foreach (string partitionId in properties.PartitionIds) { Console.WriteLine($"\t\tPartition Id: { partitionId }"); } } // At this point, our client has passed its "using" scope and has safely been disposed of. We have no // further obligations. Console.WriteLine(); }
public AzureEventHubService(string connectionString, string eventHubName) { // Workaround for 5.0 until new package is released // https://github.com/Azure/azure-sdk-for-net/issues/13899 EventHubProducerClientOptions ehpco = new EventHubProducerClientOptions(); ehpco.ConnectionOptions.TransportType = EventHubsTransportType.AmqpWebSockets; client = new EventHubProducerClient(connectionString, eventHubName, ehpco); }
public void GetPublishingOptionsOrDefaultForPartitionDefaultsWhenNoPartitionIsSpecified(string partitionId) { var options = new EventHubProducerClientOptions(); options.PartitionOptions.Add("1", new PartitionPublishingOptionsInternal { ProducerGroupId = 1 }); Assert.That(options.GetPublishingOptionsOrDefaultForPartition(partitionId), Is.EqualTo(default(PartitionPublishingOptionsInternal))); }
public void GetPublishingOptionsOrDefaultForPartitionDefaultsWhenNoPartitionIsFound() { var options = new EventHubProducerClientOptions(); options.PartitionOptions.Add("1", new PartitionPublishingOptions { ProducerGroupId = 1 }); Assert.That(options.GetPublishingOptionsOrDefaultForPartition("0"), Is.EqualTo(default(PartitionPublishingOptions))); }
public async Task GetPartitionPropertiesUsesTheRetryPolicy() { var mockConnection = new MockConnection(); var retryPolicy = Mock.Of<EventHubsRetryPolicy>(); var options = new EventHubProducerClientOptions { RetryOptions = new RetryOptions { CustomRetryPolicy = retryPolicy } }; var producer = new EventHubProducerClient(mockConnection, options); await producer.GetPartitionPropertiesAsync("1"); Assert.That(mockConnection.GetPartitionPropertiesInvokedWith, Is.SameAs(retryPolicy), "Either the call was not delegated or the retry policy was not passed."); }
public EventHubProducerClient CreateEventHubClient(string eventHubName) { var options = new EventHubProducerClientOptions(); _configureOptions?.Invoke(options); var client = !string.IsNullOrWhiteSpace(HostSettings.ConnectionString) ? new EventHubProducerClient(HostSettings.ConnectionString, eventHubName, options) : new EventHubProducerClient(HostSettings.FullyQualifiedNamespace, eventHubName, HostSettings.TokenCredential, options); return(client); }
public async Task ProducerCanInitializeWithPartialPartitionOptions() { await using (EventHubScope scope = await EventHubScope.CreateAsync(2)) { var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); var options = new EventHubProducerClientOptions { EnableIdempotentPartitions = true }; var cancellationSource = new CancellationTokenSource(); cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); var partition = default(string); var partitionProperties = default(PartitionPublishingProperties); // Create a producer for a small scope that will Send some events and read the properties. await using (var initialProducer = new EventHubProducerClient(connectionString, options)) { partition = (await initialProducer.GetPartitionIdsAsync(cancellationSource.Token)).Last(); await initialProducer.SendAsync(EventGenerator.CreateEvents(10), new SendEventOptions { PartitionId = partition }, cancellationSource.Token); partitionProperties = await initialProducer.GetPartitionPublishingPropertiesAsync(partition); } // Create a new producer using the previously read properties to set options for the partition. options.PartitionOptions.Add(partition, new PartitionPublishingOptions { ProducerGroupId = partitionProperties.ProducerGroupId, OwnerLevel = partitionProperties.OwnerLevel }); Assert.That(options.PartitionOptions[partition].StartingSequenceNumber.HasValue, Is.False, "The partition options should not specifiy a starting sequence number."); await using var producer = new EventHubProducerClient(connectionString, options); // Verify that the properties were fully initialized when using partial options. partitionProperties = await producer.GetPartitionPublishingPropertiesAsync(partition); Assert.That(partitionProperties, Is.Not.Null, "The properties should have been created."); Assert.That(partitionProperties.IsIdempotentPublishingEnabled, Is.True, "Idempotent publishing should be enabled."); Assert.That(partitionProperties.ProducerGroupId.HasValue, Is.True, "The producer group identifier should have a value."); Assert.That(partitionProperties.OwnerLevel.HasValue, Is.True, "The owner level should have a value."); Assert.That(partitionProperties.LastPublishedSequenceNumber.HasValue, Is.True, "The last published sequence number should have a value."); // Ensure that the state supports publishing. Assert.That(async() => await producer.SendAsync(EventGenerator.CreateEvents(10), new SendEventOptions { PartitionId = partition }, cancellationSource.Token), Throws.Nothing); } }
public EventHubProducerSharedContext(IBusInstance busInstance, SendObservable sendObservers, ISendPipe sendPipe, ISerializationConfiguration serializationConfiguration, IHostSettings hostSettings, EventHubProducerClientOptions options) { SendObservers = sendObservers; SendPipe = sendPipe; _busInstance = busInstance; _serializationConfiguration = serializationConfiguration; _hostSettings = hostSettings; _options = options; _clients = new ConcurrentDictionary <string, EventHubProducerClient>(); }
public void CreateProducerCreatesDefaultWhenNoOptionsArePassed() { var expected = new EventHubProducerClientOptions(); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, new EventHubConnectionOptions()); mockClient.CreateTransportProducer(null); Assert.That(mockClient.ProducerOptions, Is.Not.Null, "The producer options should have been set."); Assert.That(mockClient.ProducerOptions.RetryOptions.IsEquivalentTo(expected.RetryOptions), Is.True, "The retries should match."); }
public void ExpandedConstructorSetsTheRetryPolicy() { var expected = Mock.Of <EventHubRetryPolicy>(); var options = new EventHubProducerClientOptions { RetryOptions = new RetryOptions { CustomRetryPolicy = expected } }; var producer = new EventHubProducerClient("namespace", "eventHub", Mock.Of <TokenCredential>(), options); Assert.That(GetRetryPolicy(producer), Is.SameAs(expected)); }
/// <summary> /// Creates a producer strongly aligned with the active protocol and transport, /// responsible for publishing <see cref="EventData" /> to the Event Hub. /// </summary> /// /// <param name="producerOptions">The set of options to apply when creating the producer.</param> /// /// <returns>A <see cref="TransportProducer"/> configured in the requested manner.</returns> /// public override TransportProducer CreateProducer(EventHubProducerClientOptions producerOptions) { Argument.AssertNotClosed(_closed, nameof(AmqpClient)); return(new AmqpProducer ( EventHubName, producerOptions.PartitionId, ConnectionScope, MessageConverter, producerOptions.RetryOptions.ToRetryPolicy() )); }
public void GetPublishingOptionsOrDefaultForPartitionReturnsTheOptionsWhenThePartitionIsFound() { var partitionId = "12"; var expectedPartitionOptions = new PartitionPublishingOptions { ProducerGroupId = 1 }; var options = new EventHubProducerClientOptions(); options.PartitionOptions.Add(partitionId, expectedPartitionOptions); Assert.That(options.GetPublishingOptionsOrDefaultForPartition(partitionId), Is.SameAs(expectedPartitionOptions)); }
public void ExpandedConstructorCreatesDefaultOptions() { var credential = new Mock<EventHubTokenCredential>(Mock.Of<TokenCredential>(), "{namespace}.servicebus.windows.net"); var expected = new EventHubProducerClientOptions().RetryOptions; var producer = new EventHubProducerClient("namespace", "eventHub", credential.Object); var policy = GetRetryPolicy(producer); Assert.That(policy, Is.Not.Null, "There should have been a retry policy set."); Assert.That(policy, Is.InstanceOf<BasicRetryPolicy>(), "The default retry policy should be a basic policy."); var actual = ((BasicRetryPolicy)policy).Options; Assert.That(actual.IsEquivalentTo(expected), Is.True, "The default retry policy should be based on the default retry options."); }
public void ConnectionConstructorCreatesDefaultOptions() { var expected = new EventHubProducerClientOptions().RetryOptions; var mockConnection = new MockConnection(); var producer = new EventHubProducerClient(mockConnection); var policy = GetRetryPolicy(producer); Assert.That(policy, Is.Not.Null, "There should have been a retry policy set."); Assert.That(policy, Is.InstanceOf<BasicRetryPolicy>(), "The default retry policy should be a basic policy."); var actual = ((BasicRetryPolicy)policy).Options; Assert.That(actual.IsEquivalentTo(expected), Is.True, "The default retry policy should be based on the default retry options."); }