Hot questions for Using Azure in azure eventhub

Top Java Programmings / Azure / azure eventhub

Question:

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.

https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-java-get-started-receive-eph

Failure while registering:     
com.microsoft.azure.eventprocessorhost.EPHConfigurationException:   
Encountered error while fetching the list of EventHub PartitionIds: 
sun.security.validator.ValidatorException: PKIX path building failed: 
sun.security.provider.certpath.SunCertPathBuilderException: 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.


Answer:

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

  1. https://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/
  2. http://nodsw.com/blog/leeland/2006/12/06-no-more-unable-find-valid-certification-path-requested-target

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.

Question:

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.


Answer:

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.

Question:

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

https://azure.microsoft.com/en-us/documentation/articles/event-hubs-java-ephjava-getstarted/

"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 com.microsoft.azure.eventprocessorhost.IEventProcessor.onOpen
- 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).

<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.7.2</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs-eph</artifactId>
<version>0.7.2</version>
</dependency>
</dependencies>

Answer:

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.

HTH!

Question:

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("mynamespace.servicebus.windows.net");
var description = manager.CreateEventHub("MyEventHub");

I want the same for java..is it possible?


Answer:

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.

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure</artifactId>
        <version>1.1.0</version>
    </dependency>
    

    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";
    azure.genericResources().define(name).withRegion(region)
            .withExistingResourceGroup(resourceGroupName).withResourceType(resourceType)
            .withProviderNamespace(providerNamespace).withoutPlan()
            .create();
    
  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.