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();
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 Token |
static final String | MANAGED_IDENTITY_AUTHENTICATION_WITH_SPACE |
Constructor Summary
Method Summary
Modifier and Type | Method and Description |
---|---|
String | getAuthentication() |
URI |
getEndpoint()
Get the endpoint which can be used to connect to the Service |
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. |
Retry |
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. |
Transport |
getTransportType()
Transport |
void |
setOperationTimeout(Duration operationTimeout)
Set the Operation |
void |
setRetryPolicy(RetryPolicy retryPolicy)
Set the retry policy. |
Connection |
setTransportType(TransportType transportType)
Set the Transport |
String | toLoggableString() |
String |
toString()
Returns an inter-operable connection string that can be used to connect to Service |
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:
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:
ConnectionStringBuilder
public ConnectionStringBuilder(String namespaceName, String entityPath, String sharedAccessSingature)
Creates a new instance from namespace, entity path and already generated SAS token.
Parameters:
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:
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:
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:
Method Details
getAuthentication
public String getAuthentication()
Returns:
getEndpoint
public URI getEndpoint()
Get the endpoint which can be used to connect to the ServiceBus Namespace
Returns:
getEntityPath
public String getEntityPath()
Get the entity path value from the connection string
Returns:
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:
getRetryPolicy
public RetryPolicy getRetryPolicy()
Get the retry policy instance that was created as part of this builder's creation.
Returns:
getSasKey
public String getSasKey()
Get the shared access policy key value from the connection string or null.
Returns:
getSasKeyName
public String getSasKeyName()
Get the shared access policy owner name from the connection string or null.
Returns:
getSharedAccessSignatureToken
public String getSharedAccessSignatureToken()
Returns the shared access signature token from the connection string or null.
Returns:
getTransportType
public TransportType getTransportType()
TransportType on which all the communication for the Service Bus created using this ConnectionString. Default value is AMQP.
Returns:
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:
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:
setTransportType
public ConnectionStringBuilder setTransportType(TransportType transportType)
Set the TransportType value in the Connection String. If no TransportType is set, this defaults to AMQP.
Parameters:
Returns:
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:
Applies to
Azure SDK for Java