ConnectionStringBuilder Class

  • java.lang.Object
    • com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder

public class ConnectionStringBuilder

This class can be used to construct a connection string which can establish communication with ServiceBus entities. It can also be used to perform basic validation on an existing connection string.

Sample Code:

ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(
                                          "ServiceBusNamespaceName", 
                                          "ServiceBusEntityName", // QueueName or TopicName or SubscriptionPath
                                          "SharedAccessSignatureKeyName", 
                                          "SharedAccessSignatureKey");
  
 String connectionString = connectionStringBuilder.toString();

A connection string is basically a string consisted of key-value pair separated by ";". Basic format is {=[;=]} where supported key name are as follow:

  • Endpoint - URL that points to the servicebus namespace
  • EntityPath - Path to the service bus entity (queue/topic/subscription/). For queues and topics, it is just the entity name. For subscriptions, path is /subscriptions/
  • SharedAccessKeyName - Key name to the corresponding shared access policy rule for the namespace, or entity.
  • SharedAccessKey - Key value for the corresponding shared access policy rule of the namespace or entity.
  • SharedAccessSignatureToken - Instead of a key name and key value, clients can provide an already generated SAS Token.
  • OperationTimeout - Default timeout to be used for all senders, receiver and clients created from this connection string.
  • RetryPolicy - Name of the retry policy.

Field Summary

Modifier and Type Field and Description
static final Duration DefaultOperationTimeout

Default operation timeout if timeout is not specified in the connection string.

static final String MANAGED_IDENTITY_AUTHENTICATION_WITHOUT_SPACE

Connection string value used for the Authentication field which indicates that Managed Identity TokenProvider will be used for authentication purposes.

static final String MANAGED_IDENTITY_AUTHENTICATION_WITH_SPACE

Constructor Summary

Constructor Description
ConnectionStringBuilder(String connectionString)

Creates a new instance from the given connection string.

ConnectionStringBuilder(String namespaceConnectionString, String entityPath)

Creates a new instance from the given connection string and entity path.

ConnectionStringBuilder(String namespaceName, String entityPath, String sharedAccessSingature)

Creates a new instance from namespace, entity path and already generated SAS token.

ConnectionStringBuilder(String namespaceName, String entityPath, String sharedAccessKeyName, String sharedAccessKey)

Creates a new instance from namespace, entity path and SAS Key name and value.

ConnectionStringBuilder(URI endpointAddress, String entityPath, String sharedAccessSingature)

Creates a new instance from endpoint address of the namesapce, entity path and already generated SAS token.

ConnectionStringBuilder(URI endpointAddress, String entityPath, String sharedAccessKeyName, String sharedAccessKey)

Creates a new instance from endpoint address of the namesapce, entity path and SAS Key name and value

Method Summary

Modifier and Type Method and Description
String getAuthentication()
URI getEndpoint()

Get the endpoint which can be used to connect to the ServiceBus Namespace

String getEntityPath()

Get the entity path value from the connection string

Duration getOperationTimeout()

Gets the duration after which a pending operation like Send or RECEIVE will time out.

RetryPolicy getRetryPolicy()

Get the retry policy instance that was created as part of this builder's creation.

String getSasKey()

Get the shared access policy key value from the connection string or null.

String getSasKeyName()

Get the shared access policy owner name from the connection string or null.

String getSharedAccessSignatureToken()

Returns the shared access signature token from the connection string or null.

TransportType getTransportType()

TransportType on which all the communication for the Service Bus created using this ConnectionString.

void setOperationTimeout(Duration operationTimeout)

Set the OperationTimeout value in the Connection String.

void setRetryPolicy(RetryPolicy retryPolicy)

Set the retry policy.

ConnectionStringBuilder setTransportType(TransportType transportType)

Set the TransportType value in the Connection String.

String toLoggableString()
String toString()

Returns an inter-operable connection string that can be used to connect to ServiceBus Namespace

Methods inherited from java.lang.Object

Field Details

DefaultOperationTimeout

public static final Duration DefaultOperationTimeout

Default operation timeout if timeout is not specified in the connection string. 30 seconds.

MANAGED_IDENTITY_AUTHENTICATION_WITHOUT_SPACE

public static final String MANAGED_IDENTITY_AUTHENTICATION_WITHOUT_SPACE

Connection string value used for the Authentication field which indicates that Managed Identity TokenProvider will be used for authentication purposes.

MANAGED_IDENTITY_AUTHENTICATION_WITH_SPACE

public static final String MANAGED_IDENTITY_AUTHENTICATION_WITH_SPACE

Constructor Details

ConnectionStringBuilder

public ConnectionStringBuilder(String connectionString)

Creates a new instance from the given connection string. ConnectionString format: Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;SharedAccessKeyName=SHARED_ACCESS_KEY_NAME;SharedAccessKey=SHARED_ACCESS_KEY or Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;SharedAccessSignatureToken=SHARED_ACCESS_SIGNATURE_TOKEN

Parameters:

connectionString - ServiceBus ConnectionString

ConnectionStringBuilder

public ConnectionStringBuilder(String namespaceConnectionString, String entityPath)

Creates a new instance from the given connection string and entity path. A connection string may or may not include the entity path. ConnectionString format: Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;SharedAccessKeyName=SHARED_ACCESS_KEY_NAME;SharedAccessKey=SHARED_ACCESS_KEY or Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;SharedAccessSignatureToken=SHARED_ACCESS_SIGNATURE_TOKEN

Parameters:

namespaceConnectionString - connections string of the ServiceBus namespace. This doesn't include the entity path.
entityPath - path to the entity within the namespace

ConnectionStringBuilder

public ConnectionStringBuilder(String namespaceName, String entityPath, String sharedAccessSingature)

Creates a new instance from namespace, entity path and already generated SAS token.

Parameters:

namespaceName - Namespace name (dns suffix - ex: .servicebus.windows.net is not required)
entityPath - Entity path. For queue or topic, use name. For subscription use <topicName>/subscriptions/<subscriptionName>
sharedAccessSingature - Shared Access Signature already generated

ConnectionStringBuilder

public ConnectionStringBuilder(String namespaceName, String entityPath, String sharedAccessKeyName, String sharedAccessKey)

Creates a new instance from namespace, entity path and SAS Key name and value.

Parameters:

namespaceName - Namespace name (dns suffix - ex: .servicebus.windows.net is not required)
entityPath - Entity path. For queue or topic, use name. For subscription use <topicName>/subscriptions/<subscriptionName>
sharedAccessKeyName - Shared Access Key name
sharedAccessKey - Shared Access Key

ConnectionStringBuilder

public ConnectionStringBuilder(URI endpointAddress, String entityPath, String sharedAccessSingature)

Creates a new instance from endpoint address of the namesapce, entity path and already generated SAS token.

Parameters:

endpointAddress - namespace level endpoint. This needs to be in the format of scheme://fullyQualifiedServiceBusNamespaceEndpointName
entityPath - Entity path. For queue or topic, use name. For subscription use <topicName>/subscriptions/<subscriptionName>
sharedAccessSingature - Shared Access Signature already generated

ConnectionStringBuilder

public ConnectionStringBuilder(URI endpointAddress, String entityPath, String sharedAccessKeyName, String sharedAccessKey)

Creates a new instance from endpoint address of the namesapce, entity path and SAS Key name and value

Parameters:

endpointAddress - namespace level endpoint. This needs to be in the format of scheme://fullyQualifiedServiceBusNamespaceEndpointName
entityPath - Entity path. For queue or topic, use name. For subscription use <topicName>/subscriptions/<subscriptionName>
sharedAccessKeyName - Shared Access Key name
sharedAccessKey - Shared Access Key

Method Details

getAuthentication

public String getAuthentication()

Returns:

Returns the authentication method.

getEndpoint

public URI getEndpoint()

Get the endpoint which can be used to connect to the ServiceBus Namespace

Returns:

Endpoint representing the service bus namespace

getEntityPath

public String getEntityPath()

Get the entity path value from the connection string

Returns:

Entity Path

getOperationTimeout

public Duration getOperationTimeout()

Gets the duration after which a pending operation like Send or RECEIVE will time out. If a timeout is not specified, it defaults to DefaultOperationTimeout This value will be used by all operations which uses this ConnectionStringBuilder, unless explicitly over-ridden.

Returns:

operationTimeout

getRetryPolicy

public RetryPolicy getRetryPolicy()

Get the retry policy instance that was created as part of this builder's creation.

Returns:

RetryPolicy applied for any operation performed using this ConnectionString

getSasKey

public String getSasKey()

Get the shared access policy key value from the connection string or null.

Returns:

Shared Access Signature key value

getSasKeyName

public String getSasKeyName()

Get the shared access policy owner name from the connection string or null.

Returns:

Shared Access Signature key name

getSharedAccessSignatureToken

public String getSharedAccessSignatureToken()

Returns the shared access signature token from the connection string or null.

Returns:

Shared Access Signature Token

getTransportType

public TransportType getTransportType()

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

Returns:

transportType

setOperationTimeout

public void setOperationTimeout(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.

Parameters:

operationTimeout - Operation Timeout

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)

Set the retry policy.

RetryPolicy is not Serialized as part of toString() and is not interoperable with ServiceBus clients in other platforms.

Parameters:

retryPolicy - RetryPolicy applied for any operation performed using this ConnectionString

setTransportType

public ConnectionStringBuilder setTransportType(TransportType transportType)

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

Parameters:

transportType - Transport Type

Returns:

the ConnectionStringBuilder instance being set.

toLoggableString

public String toLoggableString()

toString

public String toString()

Returns an inter-operable connection string that can be used to connect to ServiceBus Namespace

Overrides:

ConnectionStringBuilder.toString()

Returns:

connection string

Applies to