public void CreateConsumerCreatesDefaultWhenNoOptionsArePassed() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expectedOptions = new EventHubConsumerOptions { Retry = clientOptions.Retry, DefaultMaximumReceiveWaitTime = clientOptions.DefaultTimeout }; var expectedPartition = "56767"; var expectedPosition = EventPosition.FromEnqueuedTime(DateTime.Parse("2015-10-27T12:00:00Z")); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); mockClient.CreateConsumer(expectedPartition, expectedPosition); var actualOptions = mockClient.ConsumerOptions; Assert.That(actualOptions, Is.Not.Null, "The consumer options should have been set."); Assert.That(actualOptions.ConsumerGroup, Is.EqualTo(expectedOptions.ConsumerGroup), "The consumer groups should match."); Assert.That(actualOptions.OwnerLevel, Is.EqualTo(expectedOptions.OwnerLevel), "The owner levels should match."); Assert.That(actualOptions.Identifier, Is.EqualTo(expectedOptions.Identifier), "The identifiers should match."); Assert.That(actualOptions.PrefetchCount, Is.EqualTo(expectedOptions.PrefetchCount), "The prefetch counts should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)actualOptions.Retry, (ExponentialRetry)expectedOptions.Retry), "The retries should match."); Assert.That(actualOptions.MaximumReceiveWaitTimeOrDefault, Is.EqualTo(expectedOptions.MaximumReceiveWaitTimeOrDefault), "The wait times should match."); }
/// <summary> /// Initializes a new instance of the <see cref="AmqpEventHubClient"/> class. /// </summary> /// /// <param name="host">The fully qualified host name for the Event Hubs namespace. This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param> /// <param name="eventHubName">The name of the specific Event Hub to connect the client to.</param> /// <param name="credential">The Azure managed identity credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.</param> /// <param name="clientOptions">A set of options to apply when configuring the client.</param> /// <param name="defaultRetryPolicy">The default retry policy to use if no retry options were specified in the <paramref name="clientOptions" />.</param> /// /// <remarks> /// As an internal type, this class performs only basic sanity checks against its arguments. It /// is assumed that callers are trusted and have performed deep validation. /// /// Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose; /// creation of clones or otherwise protecting the parameters is assumed to be the purview of the /// caller. /// </remarks> /// public AmqpEventHubClient(string host, string eventHubName, TokenCredential credential, EventHubClientOptions clientOptions, EventHubRetryPolicy defaultRetryPolicy) : this(host, eventHubName, credential, clientOptions, defaultRetryPolicy, null, null) { }
public void CreateReceiverCreatesDefaultWhenNoOptionsArePassed() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expectedOptions = new EventReceiverOptions { Retry = clientOptions.Retry, DefaultMaximumReceiveWaitTime = clientOptions.DefaultTimeout }; var expectedPartition = "56767"; var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); mockClient.CreateReceiver(expectedPartition); var actualOptions = mockClient.ReceiverOptions; Assert.That(actualOptions, Is.Not.Null, "The receiver options should have been set."); Assert.That(actualOptions.BeginReceivingAt.Offset, Is.EqualTo(expectedOptions.BeginReceivingAt.Offset), "The beginning position to receive should match."); Assert.That(actualOptions.ConsumerGroup, Is.EqualTo(expectedOptions.ConsumerGroup), "The consumer groups should match."); Assert.That(actualOptions.ExclusiveReceiverPriority, Is.EqualTo(expectedOptions.ExclusiveReceiverPriority), "The exclusive priorities should match."); Assert.That(actualOptions.Identifier, Is.EqualTo(expectedOptions.Identifier), "The identifiers should match."); Assert.That(actualOptions.PrefetchCount, Is.EqualTo(expectedOptions.PrefetchCount), "The prefetch counts should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)actualOptions.Retry, (ExponentialRetry)expectedOptions.Retry), "The retries should match."); Assert.That(actualOptions.MaximumReceiveWaitTimeOrDefault, Is.EqualTo(expectedOptions.MaximumReceiveWaitTimeOrDefault), "The wait times should match."); }
public void CreateEventSenderCreatesDefaultWhenNoOptionsArePassed() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expected = new SenderOptions { Retry = clientOptions.Retry, Timeout = clientOptions.DefaultTimeout }; var actual = default(SenderOptions); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new Mock <EventHubClient>(connectionString, clientOptions) { CallBase = true }; mockClient .Protected() .Setup <EventSender>("BuildEventSender", ItExpr.IsAny <ConnectionType>(), ItExpr.IsAny <string>(), ItExpr.IsAny <SenderOptions>()) .Returns(Mock.Of <EventSender>()) .Callback <ConnectionType, string, SenderOptions>((type, path, options) => actual = options); mockClient.Object.CreateSender(); Assert.That(actual, Is.Not.Null, "The sender options should have been set."); Assert.That(actual.PartitionId, Is.EqualTo(expected.PartitionId), "The partition identifiers should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)actual.Retry, (ExponentialRetry)expected.Retry), "The retries should match."); Assert.That(actual.TimeoutOrDefault, Is.EqualTo(expected.TimeoutOrDefault), "The timeouts should match."); }
public virtual EventProcessorClient ResolveEventProcessorClient(IServiceProvider serviceProvider) { var eventProcessorOptions = new EventHubClientOptions(); var applicationType = GetConsoleApplicationType(); if (applicationType == _normalizationAppType) { Configuration.GetSection("InputEventHub").Bind(eventProcessorOptions); } else if (applicationType == _measurementToFhirAppType) { Configuration.GetSection("NormalizationEventHub").Bind(eventProcessorOptions); } else { throw new Exception($"Unable to determine event processor options from application type {applicationType}"); } var eventProcessorClientFactory = serviceProvider.GetRequiredService <IEventProcessorClientFactory>(); var eventProcessorClientOptions = new EventProcessorClientOptions(); eventProcessorClientOptions.MaximumWaitTime = TimeSpan.FromSeconds(60); var storageCheckpointClient = serviceProvider.GetRequiredService <StorageCheckpointClient>(); var incomingEventReader = eventProcessorClientFactory.CreateProcessorClient(storageCheckpointClient.GetBlobContainerClient(), eventProcessorOptions, eventProcessorClientOptions); return(incomingEventReader); }
public async Task ClientCanConnectToEventHubsUsingArguments() { await using (var scope = await EventHubScope.CreateAsync(1)) { var clientOptions = new EventHubClientOptions(); var connectionString = TestEnvironment.BuildConnectionStringForEventHub(scope.EventHubName); var connectionProperties = ConnectionStringParser.Parse(connectionString); var credential = new SharedAccessSignatureCredential ( new SharedAccessSignature ( $"{ clientOptions.TransportType.GetUriScheme() }://{ connectionProperties.Endpoint.Host }/{ connectionProperties.EventHubPath }".ToLowerInvariant(), connectionProperties.SharedAccessKeyName, connectionProperties.SharedAccessKey, TimeSpan.FromHours(4) ) ); await using (var client = new EventHubClient(connectionProperties.Endpoint.Host, connectionProperties.EventHubPath, credential)) { Assert.That(() => client.GetPropertiesAsync(), Throws.Nothing); } } }
public virtual StorageCheckpointClient ResolveCheckpointClient(IServiceProvider serviceProvider) { var applicationType = GetConsoleApplicationType(); var storageOptions = new StorageCheckpointOptions(); Configuration.GetSection(StorageCheckpointOptions.Settings).Bind(storageOptions); var checkpointContainerOptions = new BlobContainerClientOptions(); Configuration.GetSection("CheckpointStorage").Bind(checkpointContainerOptions); var factory = serviceProvider.GetRequiredService <BlobContainerClientFactory>(); var checkpointBlobClient = factory.CreateStorageClient(checkpointContainerOptions); var logger = serviceProvider.GetRequiredService <ITelemetryLogger>(); var eventProcessorOptions = new EventHubClientOptions(); if (applicationType == _normalizationAppType) { Configuration.GetSection("InputEventHub").Bind(eventProcessorOptions); } else if (applicationType == _measurementToFhirAppType) { Configuration.GetSection("NormalizationEventHub").Bind(eventProcessorOptions); } storageOptions.BlobPrefix = $"{applicationType}/{storageOptions.BlobPrefix}"; var checkpointClient = new StorageCheckpointClient(checkpointBlobClient, storageOptions, eventProcessorOptions, logger); return(checkpointClient); }
public InjectableTransportClientMock(TransportEventHubClient transportClient, string connectionString, EventHubClientOptions clientOptions = default) : base(connectionString, clientOptions) { TransportClient = transportClient; SetTransportClient(transportClient); }
public async Task ClientCannotRetrieveMetadataWhenProxyIsInvalid() { await using (var scope = await EventHubScope.CreateAsync(1)) { var connectionString = TestEnvironment.BuildConnectionStringForEventHub(scope.EventHubName); var clientOptions = new EventHubClientOptions { Proxy = new WebProxy("http://1.2.3.4:9999"), TransportType = TransportType.AmqpWebSockets, RetryOptions = new RetryOptions { TryTimeout = TimeSpan.FromMinutes(2) } }; await using (var client = new EventHubClient(connectionString)) await using (var invalidProxyClient = new EventHubClient(connectionString, clientOptions)) { var partition = (await client.GetPartitionIdsAsync()).First(); Assert.That(async() => await invalidProxyClient.GetPartitionIdsAsync(), Throws.InstanceOf <WebSocketException>().Or.InstanceOf <TimeoutException>()); Assert.That(async() => await invalidProxyClient.GetPropertiesAsync(), Throws.InstanceOf <WebSocketException>().Or.InstanceOf <TimeoutException>()); Assert.That(async() => await invalidProxyClient.GetPartitionPropertiesAsync(partition), Throws.InstanceOf <WebSocketException>().Or.InstanceOf <TimeoutException>()); } } }
public async Task CreateClientUsesDefaultPolicyForTheRetryPolicy() { var retryOptions = new RetryOptions { MaximumRetries = 99, MaximumDelay = TimeSpan.FromHours(72), Delay = TimeSpan.FromSeconds(27) }; var options = new EventHubClientOptions(); options.ClearRetryOptions(); var host = "my.eventhub.com"; var eventHubPath = "some-path"; var resource = $"amqps://{ host }/{ eventHubPath }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetryPolicy = new BasicRetryPolicy(retryOptions); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options, () => defaultRetryPolicy); try { Assert.That(client.RetryPolicy, Is.Not.Null, "The client should have a retry policy."); Assert.That(client.RetryPolicy, Is.InstanceOf <TrackOneRetryPolicy>(), "The client should always use the track one compatibility retry policy."); var clientPolicy = GetSourcePolicy((TrackOneRetryPolicy)client.RetryPolicy); Assert.That(clientPolicy, Is.SameAs(defaultRetryPolicy), "The default policy should have been used as the source policy."); } finally { await client?.CloseAsync(); } }
public void CreateConsumerCreatesDefaultWhenOptionsAreNotSet() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expectedOptions = new EventHubConsumerOptions { ConsumerGroup = "SomeGroup", OwnerLevel = 251, Identifier = "Bob", PrefetchCount = 600, Retry = clientOptions.Retry, DefaultMaximumReceiveWaitTime = clientOptions.DefaultTimeout }; var expectedPartition = "56767"; var expectedPosition = EventPosition.FromSequenceNumber(123); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); mockClient.CreateConsumer(expectedPartition, expectedPosition, expectedOptions); var actualOptions = mockClient.ConsumerOptions; Assert.That(actualOptions, Is.Not.Null, "The consumer options should have been set."); Assert.That(actualOptions, Is.Not.SameAs(expectedOptions), "A clone of the options should have been made."); Assert.That(actualOptions.ConsumerGroup, Is.EqualTo(expectedOptions.ConsumerGroup), "The consumer groups should match."); Assert.That(actualOptions.OwnerLevel, Is.EqualTo(expectedOptions.OwnerLevel), "The owner levels should match."); Assert.That(actualOptions.Identifier, Is.EqualTo(expectedOptions.Identifier), "The identifiers should match."); Assert.That(actualOptions.PrefetchCount, Is.EqualTo(expectedOptions.PrefetchCount), "The prefetch counts should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)actualOptions.Retry, (ExponentialRetry)expectedOptions.Retry), "The retries should match."); Assert.That(actualOptions.MaximumReceiveWaitTimeOrDefault, Is.EqualTo(expectedOptions.MaximumReceiveWaitTimeOrDefault), "The wait times should match."); }
public void CreateProducerCreatesDefaultWhenOptionsAreNotSet() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var producerOptions = new EventHubProducerOptions { PartitionId = "123", Retry = null, Timeout = TimeSpan.Zero }; var expected = new EventHubProducerOptions { PartitionId = producerOptions.PartitionId, Retry = clientOptions.Retry, Timeout = clientOptions.DefaultTimeout }; var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); mockClient.CreateProducer(producerOptions); Assert.That(mockClient.ProducerOptions, Is.Not.Null, "The producer options should have been set."); Assert.That(mockClient.ProducerOptions, Is.Not.SameAs(producerOptions), "The options should have been cloned."); Assert.That(mockClient.ProducerOptions.PartitionId, Is.EqualTo(expected.PartitionId), "The partition identifiers should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)mockClient.ProducerOptions.Retry, (ExponentialRetry)expected.Retry), "The retries should match."); Assert.That(mockClient.ProducerOptions.TimeoutOrDefault, Is.EqualTo(expected.TimeoutOrDefault), "The timeouts should match."); }
public async Task CreateClientPopulatesTheProxy() { var options = new EventHubClientOptions { TransportType = TransportType.AmqpWebSockets, Proxy = Mock.Of <IWebProxy>() }; var host = "my.eventhub.com"; var eventHubPath = "some-path"; var resource = $"amqps://{ host }/{ eventHubPath }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetry = Mock.Of <EventHubRetryPolicy>(); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options, () => defaultRetry); try { Assert.That(client.WebProxy, Is.SameAs(options.Proxy), "The client should honor the proxy."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientTranslatesTheTransportType(TransportType connectionType) { var options = new EventHubClientOptions { TransportType = connectionType }; var host = "my.eventhub.com"; var eventHubPath = "some-path"; var resource = $"amqps://{ host }/{ eventHubPath }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetry = Mock.Of <EventHubRetryPolicy>(); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options, () => defaultRetry); try { if (connectionType.ToString().ToLower().Contains("websockets")) { Assert.That(client.ConnectionStringBuilder.TransportType.ToString().ToLower(), Contains.Substring("websockets"), "The transport type should be based on WebSockets."); } else { Assert.That(client.ConnectionStringBuilder.TransportType.ToString().ToLower(), Does.Not.Contain("websockets"), "The transport type should be based on TCP."); } } finally { await client?.CloseAsync(); } }
/// <summary> /// Initializes a new instance of the <see cref="TrackOneEventHubClient"/> class. /// </summary> /// /// <param name="host">The fully qualified host name for the Event Hubs namespace. This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param> /// <param name="eventHubName">The name of the specific Event Hub to connect the client to.</param> /// <param name="credential">The Azure managed identity credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requeseted Event Hub, depending on Azure configuration.</param> /// <param name="clientOptions">A set of options to apply when configuring the client.</param> /// <param name="defaultRetryPolicy">The default retry policy to use if no retry options were specified in the <paramref name="clientOptions" />.</param> /// /// <remarks> /// As an internal type, this class performs only basic sanity checks against its arguments. It /// is assumed that callers are trusted and have performed deep validation. /// /// Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose; /// creation of clones or otherwise protecting the parameters is assumed to be the purview of the /// caller. /// </remarks> /// public TrackOneEventHubClient(string host, string eventHubName, TokenCredential credential, EventHubClientOptions clientOptions, EventHubRetryPolicy defaultRetryPolicy) : this(host, eventHubName, credential, clientOptions, defaultRetryPolicy, CreateClient) { }
/// <summary> /// Creates the track one Event Hub client instance for inner use, handling any necessary translation between track two /// and track one concepts/types. /// </summary> /// /// <param name="host">The fully qualified host name for the Event Hubs namespace. This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param> /// <param name="eventHubPath">The path of the specific Event Hub to connect the client to.</param> /// <param name="credential">The Azure managed identity credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requeseted Event Hub, depending on Azure configuration.</param> /// <param name="clientOptions">A set of options to apply when configuring the client.</param> /// /// <returns>The <see cref="TrackOne.EventHubClient" /> to use.</returns> /// internal static TrackOne.EventHubClient CreateClient(string host, string eventHubPath, TokenCredential credential, EventHubClientOptions clientOptions) { // Translate the connection type into the corresponding Track One transport type. TrackOne.TransportType transportType; switch (clientOptions.TransportType) { case TransportType.AmqpTcp: transportType = TrackOne.TransportType.Amqp; break; case TransportType.AmqpWebSockets: transportType = TrackOne.TransportType.AmqpWebSockets; break; default: throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidTransportType, clientOptions.TransportType.ToString(), nameof(clientOptions.TransportType))); } // Translate the provided credential into a Track One token provider. TokenProvider tokenProvider; switch (credential) { case SharedAccessSignatureCredential sasCredential: tokenProvider = new TrackOneSharedAccessTokenProvider(sasCredential.SharedAccessSignature); break; case EventHubTokenCredential eventHubCredential: tokenProvider = new TrackOneGenericTokenProvider(eventHubCredential); break; default: throw new ArgumentException(Resources.UnsupportedCredential, nameof(credential)); } // Create the endpoint for the client. var endpointBuilder = new UriBuilder { Scheme = clientOptions.TransportType.GetUriScheme(), Host = host, Path = eventHubPath, Port = -1, }; // Build and configure the client. var client = TrackOne.EventHubClient.Create(endpointBuilder.Uri, eventHubPath, tokenProvider, clientOptions.DefaultTimeout, transportType); client.WebProxy = clientOptions.Proxy; return(client); }
public void ConstructorWithExpandedArgumentsValidatesOptions() { var invalidOptions = new EventHubClientOptions { TransportType = TransportType.AmqpTcp, Proxy = Mock.Of <IWebProxy>() }; Assert.That(() => new EventHubClient("host", "path", Mock.Of <TokenCredential>(), invalidOptions), Throws.ArgumentException, "The cexpanded argument onstructor should validate client options"); }
public void CreateFailsForUnknownCredentialType() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubName = "some-path"; var credential = Mock.Of <TokenCredential>(); Assert.That(() => TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => Mock.Of <EventHubRetryPolicy>()), Throws.InstanceOf <ArgumentException>()); }
public void CreateFailsForUnknownCredentialType() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubPath = "some-path"; var credential = Mock.Of <TokenCredential>(); Assert.That(() => TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options), Throws.InstanceOf <NotImplementedException>()); }
public void ConstructorWithConnectionStringValidatesOptions() { var fakeConnection = "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"; var invalidOptions = new EventHubClientOptions { TransportType = TransportType.AmqpTcp, Proxy = Mock.Of <IWebProxy>() }; Assert.That(() => new EventHubClient(fakeConnection, invalidOptions), Throws.ArgumentException, "The connection string constructor should validate client options"); }
public InjectableTransportClientMock(TransportEventHubClient transportClient, string host, string eventHubPath, TokenCredential credential, EventHubClientOptions clientOptions = default) : base(host, eventHubPath, credential, clientOptions) { TransportClient = transportClient; SetTransportClient(transportClient); }
public void DefaultTimeoutUsesDefaultValueIfNotSpecified() { var options = new EventHubClientOptions(); var defaultTimeoutValue = options.TimeoutOrDefault; options.DefaultTimeout = TimeSpan.Zero; Assert.That(options.DefaultTimeout, Is.EqualTo(TimeSpan.Zero), "The value supplied by the caller should be preserved."); Assert.That(options.TimeoutOrDefault, Is.EqualTo(defaultTimeoutValue), "The timeout value should be defaulted internally."); }
public InjectableMockClient(string host, string eventHubName, TokenCredential credential, EventHubClientOptions clientOptions, EventHubRetryPolicy defaultRetryPolicy, AmqpConnectionScope connectionScope, AmqpMessageConverter messageConverter) : base(host, eventHubName, credential, clientOptions, defaultRetryPolicy, connectionScope, messageConverter) { }
public virtual IAsyncCollector <IMeasurement> ResolveEventCollector(IServiceProvider serviceProvider) { var eventHubProducerOptions = new EventHubClientOptions(); Configuration.GetSection("NormalizationEventHub").Bind(eventHubProducerOptions); var eventHubProducerFactory = serviceProvider.GetRequiredService <IEventProducerClientFactory>(); var eventHubProducerClient = eventHubProducerFactory.GetEventHubProducerClient(eventHubProducerOptions); return(new MeasurementToEventMessageAsyncCollector(new EventHubProducerService(eventHubProducerClient))); }
public async Task CloseAsyncDoesNotDelegateIfTheClientWasNotCreated() { var options = new EventHubClientOptions(); var host = "http://my.eventhub.com"; var eventHubPath = "some-path"; var signature = new SharedAccessSignature(options.TransportType, host, eventHubPath, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var mock = new ObservableClientMock(host, eventHubPath, credential, options); var client = new TrackOneEventHubClient(host, eventHubPath, credential, options, (host, path, credential, options) => mock); await client.CloseAsync(default);
public void ContructorWithExpandedArgumentsCreatesTheTransportClient() { var host = "my.eventhubs.com"; var path = "some-hub"; var keyName = "aWonderfulKey"; var key = "ABC4223"; var options = new EventHubClientOptions { TransportType = TransportType.AmqpTcp }; var signature = new SharedAccessSignature(options.TransportType, host, path, keyName, key); var client = new EventHubClient(host, path, new SharedAccessSignatureCredential(signature), options); Assert.That(client.InnerClient, Is.Not.Null); }
public void TransportClientReceivesClonedOptions(ReadableOptionsMock client, EventHubClientOptions constructorOptions, string constructorDescription) { var options = client.TransportClientOptions; Assert.That(options, Is.Not.Null, $"The { constructorDescription } constructor should have set the options."); Assert.That(options, Is.Not.SameAs(constructorOptions), $"The { constructorDescription } constructor should have cloned the options."); Assert.That(options.TransportType, Is.EqualTo(constructorOptions.TransportType), $"The { constructorDescription } constructor should have the correct connection type."); Assert.That(options.DefaultTimeout, Is.EqualTo(constructorOptions.DefaultTimeout), $"The { constructorDescription } constructor should have the correct default timeout."); Assert.That(options.Proxy, Is.EqualTo(constructorOptions.Proxy), $"The { constructorDescription } constructor should have the correct proxy."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)options.Retry, (ExponentialRetry)constructorOptions.Retry), $"The { constructorDescription } constructor should have the correct retry."); }
/// <summary> /// Initializes a new instance of the <see cref="TrackOneEventHubClient"/> class. /// </summary> /// /// <param name="host">The fully qualified host name for the Event Hubs namespace. This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param> /// <param name="eventHubPath">The path of the specific Event Hub to connect the client to.</param> /// <param name="credential">The Azure managed identity credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requeseted Event Hub, depending on Azure configuration.</param> /// <param name="clientOptions">A set of options to apply when configuring the client.</param> /// <param name="eventHubClientFactory">A delegate that can be used for creation of the <see cref="TrackOne.EventHubClient" /> to which operations are delegated to.</param> /// /// <remarks> /// As an internal type, this class performs only basic sanity checks against its arguments. It /// is assumed that callers are trusted and have performed deep validation. /// /// Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose; /// creation of clones or otherwise protecting the parameters is assumed to be the purview of the /// caller. /// </remarks> /// internal TrackOneEventHubClient(string host, string eventHubPath, TokenCredential credential, EventHubClientOptions clientOptions, Func <string, string, TokenCredential, EventHubClientOptions, TrackOne.EventHubClient> eventHubClientFactory) { Guard.ArgumentNotNullOrEmpty(nameof(host), host); Guard.ArgumentNotNullOrEmpty(nameof(eventHubPath), eventHubPath); Guard.ArgumentNotNull(nameof(credential), credential); Guard.ArgumentNotNull(nameof(clientOptions), clientOptions); _trackOneClient = new Lazy <TrackOne.EventHubClient>(() => eventHubClientFactory(host, eventHubPath, credential, clientOptions), LazyThreadSafetyMode.PublicationOnly); }
public void ConstructorCreatesDefaultOptions(ReadableOptionsMock client, string constructorDescription) { var defaultOptions = new EventHubClientOptions(); var options = client.ClientOptions; Assert.That(options, Is.Not.Null, $"The { constructorDescription } constructor should have set default options."); Assert.That(options, Is.Not.SameAs(defaultOptions), $"The { constructorDescription } constructor should not have the same options instance."); Assert.That(options.TransportType, Is.EqualTo(defaultOptions.TransportType), $"The { constructorDescription } constructor should have the correct connection type."); Assert.That(options.DefaultTimeout, Is.EqualTo(defaultOptions.DefaultTimeout), $"The { constructorDescription } constructor should have the correct default timeout."); Assert.That(options.Proxy, Is.EqualTo(defaultOptions.Proxy), $"The { constructorDescription } constructor should have the correct proxy."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)options.Retry, (ExponentialRetry)defaultOptions.Retry), $"The { constructorDescription } constructor should have the correct retry."); }
public void BuildTransportClientAllowsLegalConnectionTypes(TransportType connectionType) { var host = "my.eventhubs.com"; var path = "some-hub"; var keyName = "aWonderfulKey"; var key = "ABC4223"; var options = new EventHubClientOptions { TransportType = connectionType }; var signature = new SharedAccessSignature(connectionType, host, path, keyName, key); var credential = new SharedAccessSignatureCredential(signature); var client = new EventHubClient(host, path, credential); Assert.That(() => client.BuildTransportClient(host, path, credential, options), Throws.Nothing); }