/// <summary> /// Initializes a new instance of the <see cref="EventHubClient"/> 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> /// public EventHubClient(string host, string eventHubPath, TokenCredential credential, EventHubClientOptions clientOptions = default) { clientOptions = clientOptions?.Clone() ?? new EventHubClientOptions(); Guard.ArgumentNotNullOrEmpty(nameof(host), host); Guard.ArgumentNotNullOrEmpty(nameof(eventHubPath), eventHubPath); Guard.ArgumentNotNull(nameof(credential), credential); ValidateClientOptions(clientOptions); switch (credential) { case SharedAccessSignatureCredential _: break; case EventHubSharedKeyCredential sharedKeyCredential: credential = sharedKeyCredential.ConvertToSharedAccessSignatureCredential(BuildResource(clientOptions.TransportType, host, eventHubPath)); break; default: credential = new EventHubTokenCredential(credential, BuildResource(clientOptions.TransportType, host, eventHubPath)); break; } EventHubPath = eventHubPath; ClientOptions = clientOptions; InnerClient = BuildTransportClient(host, eventHubPath, credential, clientOptions); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubClient"/> class. /// </summary> /// /// <param name="connectionString">The connection string to use for connecting to the Event Hubs namespace; it is expected that the Event Hub path and SAS token are contained in this connection string.</param> /// <param name="eventHubPath">The path of the specific Event Hub to connect the client to.</param> /// <param name="clientOptions">A set of options to apply when configuring the client.</param> /// /// <remarks> /// If the connection string is copied from the Event Hub itself, it will contain the path to the desired Event Hub, /// and can be used directly without passing the <paramref name="eventHubPath" />. The path to the Event Hub should be /// passed only once, either as part of the connection string or separately. /// </remarks> /// public EventHubClient(string connectionString, string eventHubPath, EventHubClientOptions clientOptions) { clientOptions = clientOptions?.Clone() ?? new EventHubClientOptions(); Guard.ArgumentNotNullOrEmpty(nameof(connectionString), connectionString); ValidateClientOptions(clientOptions); var connectionStringProperties = ParseConnectionString(connectionString); ValidateConnectionProperties(connectionStringProperties, eventHubPath, nameof(connectionString)); var eventHubsHostName = connectionStringProperties.Endpoint.Host; if (String.IsNullOrEmpty(eventHubPath)) { eventHubPath = connectionStringProperties.EventHubPath; } var sharedAccessSignature = new SharedAccessSignature ( BuildResource(clientOptions.TransportType, eventHubsHostName, eventHubPath), connectionStringProperties.SharedAccessKeyName, connectionStringProperties.SharedAccessKey ); ClientOptions = clientOptions; EventHubPath = eventHubPath; InnerClient = BuildTransportClient(eventHubsHostName, eventHubPath, new SharedAccessSignatureCredential(sharedAccessSignature), clientOptions); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubClient"/> class. /// </summary> /// /// <param name="connectionString">The connection string to use for connecting to the Event Hubs namespace; it is expected that the Event Hub path and SAS token are contained in this connection string.</param> /// <param name="clientOptions">A set of options to apply when configuring the client.</param> /// /// <remarks> /// If the connection string is copied from the Event Hubs namespace, it will likely not contain the path to the desired Event Hub, /// which is needed. In this case, the path can be added manually by adding ";EntityPath=[[ EVENT HUB NAME ]]" to the end of the /// connection string. For example, ";EntityPath=telemetry-hub". /// /// If you have defined a shared access policy directly on the Event Hub itself, then copying the connection string from that /// Event Hub will result in a connection string that contains the path. /// </remarks> /// public EventHubClient(string connectionString, EventHubClientOptions clientOptions) { Guard.ArgumentNotNullOrEmpty(nameof(connectionString), connectionString); ValidateClientOptions(clientOptions); var connectionStringProperties = ParseConnectionString(connectionString); ValidateConnectionStringProperties(connectionStringProperties, nameof(connectionString)); ClientOptions = clientOptions?.Clone() ?? new EventHubClientOptions(); EventHubPath = connectionStringProperties.EventHubPath; }
/// <summary> /// Initializes a new instance of the <see cref="EventHubClient"/> 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> /// public EventHubClient(string host, string eventHubPath, TokenCredential credential, EventHubClientOptions clientOptions = default) { Guard.ArgumentNotNullOrEmpty(nameof(host), host); Guard.ArgumentNotNullOrEmpty(nameof(eventHubPath), eventHubPath); Guard.ArgumentNotNull(nameof(credential), credential); ValidateClientOptions(clientOptions); EventHubPath = eventHubPath; Credential = credential; ClientOptions = clientOptions?.Clone() ?? new EventHubClientOptions(); }