Class WebPubSubServiceClientBuilder

java.lang.Object
com.azure.messaging.webpubsub.WebPubSubServiceClientBuilder
All Implemented Interfaces:
AzureKeyCredentialTrait<WebPubSubServiceClientBuilder>, ConfigurationTrait<WebPubSubServiceClientBuilder>, ConnectionStringTrait<WebPubSubServiceClientBuilder>, EndpointTrait<WebPubSubServiceClientBuilder>, HttpTrait<WebPubSubServiceClientBuilder>, TokenCredentialTrait<WebPubSubServiceClientBuilder>

This class provides a fluent builder API to aid the configuration and instantiation of sync and async Azure Web Pub Sub clients, using the buildClient and buildAsyncClient methods respectively.

To fully configure a Azure Web Pub Sub client, it is necessary to supply a connection string retrieved from the Azure Portal, or else a combination of credential and endpoint.

An Azure Web Pub Sub client is required to connect to a specific hub. An exception will be thrown when the build methods are called if the hub value is null or an empty String.

Code Samples

 WebPubSubServiceAsyncClient client = new WebPubSubServiceClientBuilder()
     .connectionString("<Insert connection string from Azure Portal>")
     .buildAsyncClient();
 

This demonstrates using the connection string provided by the Azure Portal. Another approach is to use the combination of credential and endpoint details, as shown below:

 WebPubSubServiceAsyncClient client = new WebPubSubServiceClientBuilder()
     .credential(new AzureKeyCredential("<Insert key from Azure Portal>"))
     .endpoint("<Insert endpoint from Azure Portal>")
     .buildAsyncClient();
 

Of course, synchronous clients may also be instantiated, by calling buildClient rather than buildAsyncClient.

 WebPubSubServiceClient client = new WebPubSubServiceClientBuilder()
     .connectionString("<Insert connection string from Azure Portal>")
     .buildClient();
 
See Also: