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, the ConnectionStringBuilder
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:
Modifier and Type | Field and Description |
---|---|
static String |
MANAGED_IDENTITY_AUTHENTICATION |
Constructor and Description |
---|
ConnectionStringBuilder()
Creates an empty
ConnectionStringBuilder . |
ConnectionStringBuilder(String connectionString)
ConnectionString format:
Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;SharedAccessKeyName=SHARED_ACCESS_KEY_NAME;SharedAccessKey=SHARED_ACCESS_KEY
|
Modifier and Type | Method and 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 relevant
EventHubException |
String |
getSasKey()
Get the shared access policy key value from the connection string
|
String |
getSasKeyName()
Get the shared access policy owner name from the connection string
|
String |
getSharedAccessSignature()
Get the shared access signature (also referred as SAS Token) from the connection string
|
TransportType |
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 string
|
ConnectionStringBuilder |
setSasKeyName(String sasKeyName)
Set the shared access policy owner name from the connection string
|
ConnectionStringBuilder |
setSharedAccessSignature(String sharedAccessSignature)
Set the shared access signature (also referred as SAS Token) from the connection string
|
ConnectionStringBuilder |
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.
|
public static final String MANAGED_IDENTITY_AUTHENTICATION
public ConnectionStringBuilder()
ConnectionStringBuilder
. 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:
public ConnectionStringBuilder(String connectionString)
connectionString
- EventHubs ConnectionStringIllegalConnectionStringFormatException
- when the format of the ConnectionString is not validpublic URI getEndpoint()
public ConnectionStringBuilder setEndpoint(URI endpoint)
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".ConnectionStringBuilder
being set.public ConnectionStringBuilder setEndpoint(String namespaceName, String domainName)
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"ConnectionStringBuilder
being set.public ConnectionStringBuilder setNamespaceName(String namespaceName)
namespaceName
- the name of the namespace to connect to.ConnectionStringBuilder
being set.public String getEventHubName()
public ConnectionStringBuilder setEventHubName(String eventHubName)
eventHubName
- the name of the Event Hub to connect to.ConnectionStringBuilder
being set.public String getSasKey()
public ConnectionStringBuilder setSasKey(String sasKey)
sasKey
- the SAS keyConnectionStringBuilder
being set.public String getSasKeyName()
public ConnectionStringBuilder setSasKeyName(String sasKeyName)
sasKeyName
- the SAS key nameConnectionStringBuilder
being set.public String getSharedAccessSignature()
public ConnectionStringBuilder setSharedAccessSignature(String sharedAccessSignature)
sharedAccessSignature
- the shared access key signatureConnectionStringBuilder
being set.public Duration getOperationTimeout()
EventHubException
public ConnectionStringBuilder setOperationTimeout(Duration operationTimeout)
ConnectionStringBuilder
, unless explicitly over-ridden.
ConnectionString with operationTimeout is not inter-operable between java and clients in other platforms.
operationTimeout
- Operation TimeoutConnectionStringBuilder
being set.public TransportType getTransportType()
TransportType.AMQP
.public ConnectionStringBuilder setTransportType(TransportType transportType)
TransportType.AMQP
.transportType
- Transport TypeConnectionStringBuilder
instance being set.public String getAuthentication()
public ConnectionStringBuilder setAuthentication(String authentication)
authentication
- ConnectionStringBuilder
instance being set.Copyright © 2019 Microsoft Corporation. All rights reserved.