I have seen many examples for creating a domain topic and event subscription using rest API's but I want to create it using the azure java sdk which is already there. any leads would greatly help. thanks
#create Topic
az eventgrid topic create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
#create Domain
az eventgrid domain create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
Include the azure-sdk-bom to your project to take a dependency on GA version of the Library.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-sdk-bom</artifactId>
<version>{bom_version_to_target}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
And add the direct dependency in the dependencies section without the version flag
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventgrid</artifactId>
</dependency>
</dependencies>
The authentication can be either a key credential, a shared access signature, or Azure Active Directory token authentication. Refer here
// For custom event
EventGridPublisherAsyncClient<BinaryData> customEventAsyncClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint of your event grid topic/domain that accepts custom event schema>")
.credential(new AzureKeyCredential("<key for the endpoint>"))
.buildCustomEventPublisherAsyncClient();
EventGridPublisherAsyncClient<CloudEvent> cloudEventAsyncClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint of your event grid topic/domain that accepts CloudEvent schema>")
.credential(new AzureSasCredential("<sas token that can access the endpoint>"))
.buildCloudEventPublisherAsyncClient();
Refer here for more information