Package com.microsoft.azure.eventhubs
Class ConnectionStringBuilder
- java.lang.Object
-
- com.microsoft.azure.eventhubs.ConnectionStringBuilder
-
public final class ConnectionStringBuilder extends Object
ConnectionStringBuilder
can be used to construct a connection string which can establish communication with Event Hub instances. In addition to constructing a connection string, theConnectionStringBuilder
can be used to modify an existing connection string.Sample Code:
// Construct a new connection string ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder() .setNamespaceName("EventHubsNamespaceName") .setEventHubName("EventHubsEntityName") .setSasKeyName("SharedAccessSignatureKeyName") .setSasKey("SharedAccessSignatureKey") string connString = connectionStringBuilder.build(); // Modify an existing connection string ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(existingConnectionString) .setEventHubName("SomeOtherEventHubsName") .setOperationTimeout(Duration.ofSeconds(30) string connString = connectionStringBuilder.build();
A connection string is basically a string consisting of key-value pairs separated by ";". The basic format is {<key>=<value>[;<key>=<value>]} where supported key name are as follow:
- Endpoint - the URL that contains the EventHubs namespace
- EntityPath - the EventHub name which you are connecting to
- SharedAccessKeyName - the key name to the corresponding shared access policy rule for the namespace, or entity.
- SharedAccessKey - the key for the corresponding shared access policy rule of the namespace or entity.
-
-
Field Summary
Fields Modifier and Type Field Description static String
MANAGED_IDENTITY_AUTHENTICATION
-
Constructor Summary
Constructors Constructor Description ConnectionStringBuilder()
Creates an emptyConnectionStringBuilder
.ConnectionStringBuilder(String connectionString)
ConnectionString format: Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;SharedAccessKeyName=SHARED_ACCESS_KEY_NAME;SharedAccessKey=SHARED_ACCESS_KEY
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getAuthentication()
Get the authentication type in the Connection String.URI
getEndpoint()
Get the endpoint which can be used to connect to the EventHub instance.String
getEventHubName()
Get the entity path value from the connection string.Duration
getOperationTimeout()
OperationTimeout is applied in erroneous situations to notify the caller about the relevantEventHubException
String
getSasKey()
Get the shared access policy key value from the connection stringString
getSasKeyName()
Get the shared access policy owner name from the connection stringString
getSharedAccessSignature()
Get the shared access signature (also referred as SAS Token) from the connection stringTransportType
getTransportType()
TransportType on which all the communication for the EventHub objects created using this ConnectionString.ConnectionStringBuilder
setAuthentication(String authentication)
Set the authentication type in the Connection String.ConnectionStringBuilder
setEndpoint(String namespaceName, String domainName)
Set an endpoint which can be used to connect to the EventHub instance.ConnectionStringBuilder
setEndpoint(URI endpoint)
Set an endpoint which can be used to connect to the EventHub instance.ConnectionStringBuilder
setEventHubName(String eventHubName)
Set the entity path value from the connection string.ConnectionStringBuilder
setNamespaceName(String namespaceName)
Set a namespace name which will be used to connect to an EventHubs instance.ConnectionStringBuilder
setOperationTimeout(Duration operationTimeout)
Set the OperationTimeout value in the Connection String.ConnectionStringBuilder
setSasKey(String sasKey)
Set the shared access policy key value from the connection stringConnectionStringBuilder
setSasKeyName(String sasKeyName)
Set the shared access policy owner name from the connection stringConnectionStringBuilder
setSharedAccessSignature(String sharedAccessSignature)
Set the shared access signature (also referred as SAS Token) from the connection stringConnectionStringBuilder
setTransportType(TransportType transportType)
Set the TransportType value in the Connection String.String
toString()
Returns an inter-operable connection string that can be used to connect to EventHubs instances.
-
-
-
Field Detail
-
MANAGED_IDENTITY_AUTHENTICATION
public static final String MANAGED_IDENTITY_AUTHENTICATION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ConnectionStringBuilder
public ConnectionStringBuilder()
Creates an emptyConnectionStringBuilder
. At minimum, a namespace name, an entity path, SAS key name, and SAS key need to be set before a valid connection string can be built.For advanced users, the following replacements can be done:
- An endpoint can be provided instead of a namespace name.
- A SAS token can be provided instead of a SAS key name and SAS key.
- Optionally, users can set an operation timeout instead of using the default value.
-
ConnectionStringBuilder
public ConnectionStringBuilder(String connectionString)
ConnectionString format: Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;SharedAccessKeyName=SHARED_ACCESS_KEY_NAME;SharedAccessKey=SHARED_ACCESS_KEY- Parameters:
connectionString
- EventHubs ConnectionString- Throws:
IllegalConnectionStringFormatException
- when the format of the ConnectionString is not valid
-
-
Method Detail
-
getEndpoint
public URI getEndpoint()
Get the endpoint which can be used to connect to the EventHub instance.- Returns:
- The currently set endpoint
-
setEndpoint
public ConnectionStringBuilder setEndpoint(URI endpoint)
Set an endpoint which can be used to connect to the EventHub instance.- Parameters:
endpoint
- is a combination of the namespace name and domain name. Together, these pieces make a valid endpoint. For example, the default domain name is "servicebus.windows.net", so a sample endpoint would look like this: "sb://namespace_name.servicebus.windows.net".- Returns:
- the
ConnectionStringBuilder
being set.
-
setEndpoint
public ConnectionStringBuilder setEndpoint(String namespaceName, String domainName)
Set an endpoint which can be used to connect to the EventHub instance.- Parameters:
namespaceName
- the name of the namespace to connect to.domainName
- identifies the domain the namespace is located in. For non-public and national clouds, the domain will not be "servicebus.windows.net". Available options include: - "servicebus.usgovcloudapi.net" - "servicebus.cloudapi.de" - "servicebus.chinacloudapi.cn"- Returns:
- the
ConnectionStringBuilder
being set.
-
setNamespaceName
public ConnectionStringBuilder setNamespaceName(String namespaceName)
Set a namespace name which will be used to connect to an EventHubs instance. This method adds "servicebus.windows.net" as the default domain name.- Parameters:
namespaceName
- the name of the namespace to connect to.- Returns:
- the
ConnectionStringBuilder
being set.
-
getEventHubName
public String getEventHubName()
Get the entity path value from the connection string.- Returns:
- Entity Path
-
setEventHubName
public ConnectionStringBuilder setEventHubName(String eventHubName)
Set the entity path value from the connection string.- Parameters:
eventHubName
- the name of the Event Hub to connect to.- Returns:
- the
ConnectionStringBuilder
being set.
-
getSasKey
public String getSasKey()
Get the shared access policy key value from the connection string- Returns:
- Shared Access Signature key
-
setSasKey
public ConnectionStringBuilder setSasKey(String sasKey)
Set the shared access policy key value from the connection string- Parameters:
sasKey
- the SAS key- Returns:
- the
ConnectionStringBuilder
being set.
-
getSasKeyName
public String getSasKeyName()
Get the shared access policy owner name from the connection string- Returns:
- Shared Access Signature key name.
-
setSasKeyName
public ConnectionStringBuilder setSasKeyName(String sasKeyName)
Set the shared access policy owner name from the connection string- Parameters:
sasKeyName
- the SAS key name- Returns:
- the
ConnectionStringBuilder
being set.
-
getSharedAccessSignature
public String getSharedAccessSignature()
Get the shared access signature (also referred as SAS Token) from the connection string- Returns:
- Shared Access Signature
-
setSharedAccessSignature
public ConnectionStringBuilder setSharedAccessSignature(String sharedAccessSignature)
Set the shared access signature (also referred as SAS Token) from the connection string- Parameters:
sharedAccessSignature
- the shared access key signature- Returns:
- the
ConnectionStringBuilder
being set.
-
getOperationTimeout
public Duration getOperationTimeout()
OperationTimeout is applied in erroneous situations to notify the caller about the relevantEventHubException
- Returns:
- operationTimeout
-
setOperationTimeout
public ConnectionStringBuilder setOperationTimeout(Duration operationTimeout)
Set the OperationTimeout value in the Connection String. This value will be used by all operations which uses thisConnectionStringBuilder
, unless explicitly over-ridden.ConnectionString with operationTimeout is not inter-operable between java and clients in other platforms.
- Parameters:
operationTimeout
- Operation Timeout- Returns:
- the
ConnectionStringBuilder
being set.
-
getTransportType
public TransportType getTransportType()
TransportType on which all the communication for the EventHub objects created using this ConnectionString. Default value isTransportType.AMQP
.- Returns:
- transportType
-
setTransportType
public ConnectionStringBuilder setTransportType(TransportType transportType)
Set the TransportType value in the Connection String. If no TransportType is set, this defaults toTransportType.AMQP
.- Parameters:
transportType
- Transport Type- Returns:
- the
ConnectionStringBuilder
instance being set.
-
getAuthentication
public String getAuthentication()
Get the authentication type in the Connection String.- Returns:
- authentication
-
setAuthentication
public ConnectionStringBuilder setAuthentication(String authentication)
Set the authentication type in the Connection String. The only valid values are "Managed Identity" or null.- Parameters:
authentication
- Authentication Type- Returns:
- the
ConnectionStringBuilder
instance being set.
-
-