Hot questions for Using Azure in azure eventhub

Top Java Programmings / Azure / azure eventhub


I'm not very used to java world, so I'm not sure if my problem is on my Azure set up, or java set up. I am getting the following exception after attempting the tutorial below.

Failure while registering:   
Encountered error while fetching the list of EventHub PartitionIds: PKIX path building failed: unable to find 
valid certification path to requested target

The exception occurs during this line from the sample:

 host.registerEventProcessor(EventProcessor.class, options).get();

I did the .NET version of the tutorial with little problem. Sending and receiving works in that case. Any insights? I've been fumbling around with no luck the last few days.


I searched for your issue and find some helpful blogs which can help solving the issue, please refer to the blogs below.


The above blogs all used the tool InstallCert to server certificate that can be added to local keystore. Please follow the README of the GitHub repository.


Given an implementation of the EventHostProcessor, how can I force replay of events from the last checkpoint within the same processor?

To be clear, assume my partition is 100 deep and I have consumed 10 messages. When I invoke this replay method, I would then want onEvent to return the first message from my previously consumed 10.

In C# this seems possible through the use of the Stopwatch but I do not see the Java equivalent.


The solution seems to be that you can either checkpoint to the high-water mark of the last consumed EventData or you can checkpoint to another EventData instance.

Such as context.checkpoint(data);

There does not seem to be a way to arbitrarily rewind to an earlier event within an EventProcessorHost.


I have an eventhub and I am sending data to it. Now I need to recieve that data. So I followed the tutorial in the eventhub page

"Receive messages with EventProcessorHost in Java"

In all the classes it is not letting me @Override. It gives me the following error.

Multiple markers at this line
- implements
- The method onOpen(PartitionContext) of type EventProcessor must override a superclass 

I have added the dependencies specified in the pom(I am using a maven project).



Change your project references to point to jdk1.8.

This is a very common error when you are trying to compile Java projects with jdk1.5. @Override annotations' specification changed in jdk1.5 to jdk1.6.



I want to know the code/class used to create azure eventhub topics in java.

I searched and found that we can create using .Net like below.

var manager = new Microsoft.ServiceBus.NamespaceManager("");
var description = manager.CreateEventHub("MyEventHub");

I want the same for it possible?


Per my experience, you need to do two steps to create a namespace and an entity for Azure Event Hubs in Java, as below.

To create Namespaces:

  1. Using Azure SDK for Java to create an EventHub namespace.

    First, add the dependency in the pom.xml file of Maven project.


    Here is my sample code using application token credential.

    String clientId = "<your client id regiested on AAD>";
    String domain = "<your talnet id or domain name>";
    String secret = "<your client key>";
    String subscription = "<your subscription id>";
    AzureTokenCredentials cred = new ApplicationTokenCredentials(clientId, domain, secret, AzureEnvironment.AZURE);
    Azure azure = Azure.configure().authenticate(cred).withSubscription(subscription);
    String name = "<your eventhub namespace name>";
    String region = "<your eventhub region like 'East Asia'>";
    String resourceGroupName = "<your resource group name>";
    String resourceType = "namespaces";
    String providerNamespace = "Microsoft.EventHub";
  2. To create an EventHub namespace via the REST API Create Or Update of Event Hubs Namespaces in Java.

To create Entities:

  1. Via the REST API Create Or Update of Event Hubs in Java.
  2. Via the REST API Create Event Hub of Entity management REST in Java.
  3. Just create entity on Azure portal as the figure below.

Otherwise, you can try to follow the document Create an EventHubs namespace, Event Hub, and consumer group to create it via ARM template in Java with Azure SDK.

azure.deployments().define("<deployment-name>").withExistingResourceGroup("<resource-group-name>").withTemplate("<template-uri>").withParameters("<parameters required in the template>").withMode(DeploymentMode.COMPLETE).create();

Hope it helps.