ConnectionStringBuilder 类

定义

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:

  • 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.

public class ConnectionStringBuilder
继承
java.lang.Object
ConnectionStringBuilder

构造函数

ConnectionStringBuilder()

Creates an empty 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:

  • 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(String connectionString)

ConnectionString format: Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;SharedAccessKeyName=SHARED_ACCESS_KEY_NAME;SharedAccessKey=SHARED_ACCESS_KEY

方法

getEndpoint()

Get the endpoint which can be used to connect to the EventHub instance.

getEventHubName()

Get the entity path value from the connection string.

getOperationTimeout()

OperationTimeout is applied in erroneous situations to notify the caller about the relevant EventHubException

getSasKey()

Get the shared access policy key value from the connection string

getSasKeyName()

Get the shared access policy owner name from the connection string

getSharedAccessSignature()

Get the shared access signature (also referred as SAS Token) from the connection string

getTransportType()

TransportType on which all the communication for the EventHub objects created using this ConnectionString. Default value is AMQP.

setEndpoint(String namespaceName, String domainName)

Set an endpoint which can be used to connect to the EventHub instance.

setEndpoint(URI endpoint)

Set an endpoint which can be used to connect to the EventHub instance.

setEventHubName(String eventHubName)

Set the entity path value from the connection string.

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.

setOperationTimeout(final Duration operationTimeout)

Set the OperationTimeout value in the Connection String. This value will be used by all operations which uses this ConnectionStringBuilder, unless explicitly over-ridden.

ConnectionString with operationTimeout is not inter-operable between java and clients in other platforms.

setSasKey(String sasKey)

Set the shared access policy key value from the connection string

setSasKeyName(String sasKeyName)

Set the shared access policy owner name from the connection string

setSharedAccessSignature(String sharedAccessSignature)

Set the shared access signature (also referred as SAS Token) from the connection string

setTransportType(final TransportType transportType)

Set the TransportType value in the Connection String. If no TransportType is set, this defaults to AMQP.

toString()

Returns an inter-operable connection string that can be used to connect to EventHubs instances.

适用于