ConnectionStringBuilder Class
- java.
lang. Object - com.
microsoft. azure. servicebus. primitives. ConnectionStringBuilder
- com.
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();
</code></pre></p>
A connection string is basically a string consisted of key-value pair separated by ";". Basic format is {{ <}key{>}={ <}value{>}[;{ <}key{>}={ <}value{>}]} 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 <topicName>/subscriptions/<subscriptionName>
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
final Duration
DefaultOperationTimeout
Default operation timeout if timeout is not specified in the connection string. 30 seconds.
Constructor Summary
Constructor
Description
ConnectionStringBuilder(final String namespaceName, final String entityPath, final String sharedAccessSingature)
Creates a new instance from namespace, entity path and already generated SAS token.
ConnectionStringBuilder(final String namespaceName, final String entityPath, final String sharedAccessKeyName, final String sharedAccessKey)
Creates a new instance from namespace, entity path and SAS Key name and value.
ConnectionStringBuilder(final URI endpointAddress, final String entityPath, final String sharedAccessSingature)
Creates a new instance from endpoint address of the namesapce, entity path and already generated SAS token.
ConnectionStringBuilder(final URI endpointAddress, final String entityPath, final String sharedAccessKeyName, final String sharedAccessKey)
Creates a new instance from endpoint address of the namesapce, entity path and SAS Key name and value
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
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
Method Summary
Modifier and Type
Method and Description
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. 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.
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. Default value is AMQP.
void
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.
void
setRetryPolicy(final RetryPolicy retryPolicy)
Set the retry policy.
RetryPolicy is not Serialized as part of toString() and is not interoperable with ServiceBus clients in other platforms.
ConnectionStringBuilder
setTransportType(final TransportType transportType)
Set the TransportType value in the Connection String. If no TransportType is set, this defaults to AMQP.
String
toLoggableString()
String
toString()
Returns an inter-operable connection string that can be used to connect to ServiceBus Namespace
Field Details
DefaultOperationTimeout
public static final Duration DefaultOperationTimeout= Duration.ofSeconds(ClientConstants.DEFAULT_OPERATION_TIMEOUT_IN_SECONDS)
Default operation timeout if timeout is not specified in the connection string. 30 seconds.
Constructor Details
ConnectionStringBuilder
public ConnectionStringBuilder(final String namespaceName, final String entityPath, final 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(final String namespaceName, final String entityPath, final String sharedAccessKeyName, final 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(final URI endpointAddress, final String entityPath, final 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(final URI endpointAddress, final String entityPath, final String sharedAccessKeyName, final 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
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
Throws:
IllegalConnectionStringFormatException
- when the format of the ConnectionString is not valid
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
Method Details
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(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.
Parameters:
operationTimeout
- Operation Timeout
setRetryPolicy
public void setRetryPolicy(final 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(final 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
Returns:
connection string
Applies to
Azure SDK for Java