EventGridPublisherClientBuilder Class

  • java.lang.Object
    • com.azure.messaging.eventgrid.EventGridPublisherClientBuilder

Implements

public final class EventGridPublisherClientBuilder
implements TokenCredentialTrait<EventGridPublisherClientBuilder>, AzureKeyCredentialTrait<EventGridPublisherClientBuilder>, AzureSasCredentialTrait<EventGridPublisherClientBuilder>, HttpTrait<EventGridPublisherClientBuilder>, ConfigurationTrait<EventGridPublisherClientBuilder>, EndpointTrait<EventGridPublisherClientBuilder>

A Builder class to create service clients that can publish events to EventGrid. This builder will construct publishers for CloudEvent, EventGridEvent, and custom events. It will do for both sync and async clients.

Sample: Create a EventGridEvent asynchronous publisher client.

// Create a client to send events of EventGridEvent schema
 EventGridPublisherAsyncClient<EventGridEvent> eventGridEventPublisherClient = new EventGridPublisherClientBuilder()
     .endpoint(System.getenv("AZURE_EVENTGRID_EVENT_ENDPOINT"))  // make sure it accepts EventGridEvent
     .credential(new AzureKeyCredential(System.getenv("AZURE_EVENTGRID_EVENT_KEY")))
     .buildEventGridEventPublisherAsyncClient();

Sample: Create a CloudEvent synchronous client

// Create a client to send events of CloudEvent schema (com.azure.core.models.CloudEvent)
 EventGridPublisherClient<CloudEvent> cloudEventPublisherClient = new EventGridPublisherClientBuilder()
     .endpoint(System.getenv("AZURE_EVENTGRID_CLOUDEVENT_ENDPOINT"))  // make sure it accepts CloudEvent
     .credential(new AzureKeyCredential(System.getenv("AZURE_EVENTGRID_CLOUDEVENT_KEY")))
     .buildCloudEventPublisherClient();

Sample: Create a custom event asynchronous client

// Create a client to send events of custom event
 EventGridPublisherAsyncClient<BinaryData> customEventPublisherClient = new EventGridPublisherClientBuilder()
     .endpoint(System.getenv("AZURE_CUSTOM_EVENT_ENDPOINT"))  // make sure it accepts custom events
     .credential(new AzureKeyCredential(System.getenv("AZURE_CUSTOM_EVENT_KEY")))
     .buildCustomEventPublisherAsyncClient();

Constructor Summary

Constructor Description
EventGridPublisherClientBuilder()

Construct a new instance with default building settings.

Method Summary

Modifier and Type Method and Description
EventGridPublisherClientBuilder addPolicy(HttpPipelinePolicy httpPipelinePolicy)
EventGridPublisherAsyncClient<CloudEvent> buildCloudEventPublisherAsyncClient()

Build a CloudEvent publisher client with asynchronous publishing methods and the current settings.

EventGridPublisherClient<CloudEvent> buildCloudEventPublisherClient()

Build a CloudEvent publisher client with synchronous publishing methods and the current settings.

EventGridPublisherAsyncClient<BinaryData> buildCustomEventPublisherAsyncClient()

Build a custom event publisher client with asynchronous publishing methods and the current settings.

EventGridPublisherClient<BinaryData> buildCustomEventPublisherClient()

Build a custom event publisher client with synchronous publishing methods and the current settings.

EventGridPublisherAsyncClient<EventGridEvent> buildEventGridEventPublisherAsyncClient()

Build an EventGridEvent publisher client with asynchronous publishing methods and the current settings.

EventGridPublisherClient<EventGridEvent> buildEventGridEventPublisherClient()

Build an EventGridEvent publisher client with synchronous publishing methods and the current settings.

EventGridPublisherClientBuilder clientOptions(ClientOptions clientOptions)
EventGridPublisherClientBuilder configuration(Configuration configuration)
EventGridPublisherClientBuilder credential(AzureKeyCredential credential)
EventGridPublisherClientBuilder credential(AzureSasCredential credential)
EventGridPublisherClientBuilder credential(TokenCredential credential)
EventGridPublisherClientBuilder endpoint(String endpoint)

Set the domain or topic endpoint.

EventGridPublisherClientBuilder httpClient(HttpClient httpClient)
EventGridPublisherClientBuilder httpLogOptions(HttpLogOptions httpLogOptions)
EventGridPublisherClientBuilder pipeline(HttpPipeline httpPipeline)
EventGridPublisherClientBuilder retryOptions(RetryOptions retryOptions)
EventGridPublisherClientBuilder retryPolicy(RetryPolicy retryPolicy)

Add a custom retry policy to the pipeline.

EventGridPublisherClientBuilder serviceVersion(EventGridServiceVersion serviceVersion)

Set the service version to use for requests to the event grid service.

Methods inherited from java.lang.Object

Constructor Details

EventGridPublisherClientBuilder

public EventGridPublisherClientBuilder()

Construct a new instance with default building settings. The endpoint and one credential method must be set in order for the client to be built.

Method Details

addPolicy

public EventGridPublisherClientBuilder addPolicy(HttpPipelinePolicy httpPipelinePolicy)

Parameters:

httpPipelinePolicy

buildCloudEventPublisherAsyncClient

public EventGridPublisherAsyncClient<CloudEvent> buildCloudEventPublisherAsyncClient()

Build a CloudEvent publisher client with asynchronous publishing methods and the current settings. An endpoint must be set, and either a pipeline with correct authentication must be set, or a credential must be set in the form of an AzureSasCredential or a AzureKeyCredential at the respective methods. All other settings have defaults and are optional.

Returns:

a publisher client with asynchronous publishing methods.

buildCloudEventPublisherClient

public EventGridPublisherClient<CloudEvent> buildCloudEventPublisherClient()

Build a CloudEvent publisher client with synchronous publishing methods and the current settings. Endpoint and a credential must be set (either keyCredential or sharedAccessSignatureCredential), all other settings have defaults and/or are optional.

Returns:

a publisher client with synchronous publishing methods.

buildCustomEventPublisherAsyncClient

public EventGridPublisherAsyncClient<BinaryData> buildCustomEventPublisherAsyncClient()

Build a custom event publisher client with asynchronous publishing methods and the current settings. An endpoint must be set, and either a pipeline with correct authentication must be set, or a credential must be set in the form of an AzureSasCredential or a AzureKeyCredential at the respective methods. All other settings have defaults and are optional.

Returns:

a publisher client with asynchronous publishing methods.

buildCustomEventPublisherClient

public EventGridPublisherClient<BinaryData> buildCustomEventPublisherClient()

Build a custom event publisher client with synchronous publishing methods and the current settings. Endpoint and a credential must be set (either keyCredential or sharedAccessSignatureCredential), all other settings have defaults and/or are optional.

Returns:

a publisher client with synchronous publishing methods.

buildEventGridEventPublisherAsyncClient

public EventGridPublisherAsyncClient<EventGridEvent> buildEventGridEventPublisherAsyncClient()

Build an EventGridEvent publisher client with asynchronous publishing methods and the current settings. An endpoint must be set, and either a pipeline with correct authentication must be set, or a credential must be set in the form of an AzureSasCredential or a AzureKeyCredential at the respective methods. All other settings have defaults and are optional.

Returns:

a publisher client with asynchronous publishing methods.

buildEventGridEventPublisherClient

public EventGridPublisherClient<EventGridEvent> buildEventGridEventPublisherClient()

Build an EventGridEvent publisher client with synchronous publishing methods and the current settings. Endpoint and a credential must be set (either keyCredential or sharedAccessSignatureCredential), all other settings have defaults and/or are optional.

Returns:

a publisher client with synchronous publishing methods.

clientOptions

public EventGridPublisherClientBuilder clientOptions(ClientOptions clientOptions)

Parameters:

clientOptions

configuration

public EventGridPublisherClientBuilder configuration(Configuration configuration)

Parameters:

configuration

credential

public EventGridPublisherClientBuilder credential(AzureKeyCredential credential)

Parameters:

credential

credential

public EventGridPublisherClientBuilder credential(AzureSasCredential credential)

Parameters:

credential

credential

public EventGridPublisherClientBuilder credential(TokenCredential credential)

Parameters:

credential

endpoint

public EventGridPublisherClientBuilder endpoint(String endpoint)

Set the domain or topic endpoint. This is the address to publish events to. It must be the full url of the endpoint instead of just the hostname.

Parameters:

endpoint - the endpoint as a url.

Returns:

the builder itself.

httpClient

public EventGridPublisherClientBuilder httpClient(HttpClient httpClient)

Parameters:

httpClient

httpLogOptions

public EventGridPublisherClientBuilder httpLogOptions(HttpLogOptions httpLogOptions)

Parameters:

httpLogOptions

pipeline

public EventGridPublisherClientBuilder pipeline(HttpPipeline httpPipeline)

Parameters:

httpPipeline

retryOptions

public EventGridPublisherClientBuilder retryOptions(RetryOptions retryOptions)

Parameters:

retryOptions

retryPolicy

public EventGridPublisherClientBuilder retryPolicy(RetryPolicy retryPolicy)

Add a custom retry policy to the pipeline. The default is RetryPolicy#RetryPolicy(). Setting this is mutually exclusive with using retryOptions(RetryOptions retryOptions).

Parameters:

retryPolicy - the retry policy to add.

Returns:

the builder itself.

serviceVersion

public EventGridPublisherClientBuilder serviceVersion(EventGridServiceVersion serviceVersion)

Set the service version to use for requests to the event grid service. See EventGridServiceVersion for more information about possible service versions.

Parameters:

serviceVersion - the service version to set. By default this will use the latest available version.

Returns:

the builder itself

Applies to