Class ConnectionStringBuilder


  • public class ConnectionStringBuilder
    extends Object
    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 {<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.
    Since:
    1.0
    • Field Detail

      • 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.
        See Also:
        Constant Field Values
      • MANAGED_IDENTITY_AUTHENTICATION_WITH_SPACE

        public static final String MANAGED_IDENTITY_AUTHENTICATION_WITH_SPACE
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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​(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​(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
      • 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​(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 Detail

      • getEndpoint

        public URI getEndpoint()
        Get the endpoint which can be used to connect to the ServiceBus Namespace
        Returns:
        Endpoint representing the service bus namespace
      • 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
      • 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
      • 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
      • 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
      • 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
      • getTransportType

        public TransportType getTransportType()
        TransportType on which all the communication for the Service Bus created using this ConnectionString. Default value is TransportType.AMQP.
        Returns:
        transportType
      • getAuthentication

        public String getAuthentication()
        Returns:
        Returns the authentication method.
      • toString

        public String toString()
        Returns an inter-operable connection string that can be used to connect to ServiceBus Namespace
        Overrides:
        toString in class Object
        Returns:
        connection string
      • toLoggableString

        public String toLoggableString()