forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
496 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...hubs/src/samples/java/com/azure/messaging/eventhubs/EventProcessorJavaDocCodeSamples.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.messaging.eventhubs; | ||
|
||
import com.azure.messaging.eventhubs.models.PartitionContext; | ||
import reactor.core.publisher.Mono; | ||
|
||
/** | ||
* Code snippets for {@link EventProcessorAsyncClient} | ||
*/ | ||
public final class EventProcessorJavaDocCodeSamples { | ||
|
||
/** | ||
* Code snippet for showing how to create a new instance of {@link EventProcessorAsyncClient}. | ||
* | ||
* @return An instance of {@link EventProcessorAsyncClient}. | ||
*/ | ||
public EventProcessorAsyncClient createInstance() { | ||
// BEGIN: com.azure.messaging.eventhubs.eventprocessorasyncclient.instantiation | ||
String connectionString = "Endpoint={endpoint};SharedAccessKeyName={sharedAccessKeyName};" | ||
+ "SharedAccessKey={sharedAccessKey};EntityPath={eventHubPath}"; | ||
EventProcessorAsyncClient eventProcessorAsyncClient = new EventHubClientBuilder() | ||
.connectionString(connectionString) | ||
.partitionProcessorFactory((PartitionProcessorImpl::new)) | ||
.consumerGroupName("consumer-group") | ||
.buildEventProcessorAsyncClient(); | ||
// END: com.azure.messaging.eventhubs.eventprocessorasyncclient.instantiation | ||
return eventProcessorAsyncClient; | ||
} | ||
|
||
/** | ||
* Code snippet for showing how to start and stop an {@link EventProcessorAsyncClient}. | ||
*/ | ||
public void startStopSample() { | ||
EventProcessorAsyncClient eventProcessorAsyncClient = createInstance(); | ||
// BEGIN: com.azure.messaging.eventhubs.eventprocessorasyncclient.startstop | ||
eventProcessorAsyncClient.start(); | ||
// do other stuff while the event processor is running | ||
eventProcessorAsyncClient.stop(); | ||
// END: com.azure.messaging.eventhubs.eventprocessorasyncclient.startstop | ||
} | ||
|
||
/** | ||
* No-op partition processor used in code snippet to demo creating an instance of {@link EventProcessorAsyncClient}. | ||
* This class will not be visible in the code snippet. | ||
*/ | ||
private static class PartitionProcessorImpl implements PartitionProcessor { | ||
|
||
PartitionContext partitionContext; | ||
CheckpointManager checkpointManager; | ||
|
||
/** | ||
* Creates new instance. | ||
* | ||
* @param partitionContext The partition context for this partition processor. | ||
* @param checkpointManager The checkpoint manager for this partition processor. | ||
*/ | ||
private PartitionProcessorImpl(PartitionContext partitionContext, CheckpointManager checkpointManager) { | ||
this.partitionContext = partitionContext; | ||
this.checkpointManager = checkpointManager; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return a representation of deferred initialization. | ||
*/ | ||
@Override | ||
public Mono<Void> initialize() { | ||
return Mono.empty(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return a representation of deferred initialization. | ||
*/ | ||
@Override | ||
public Mono<Void> processEvent(EventData eventData) { | ||
return Mono.empty(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param throwable The {@link Throwable} that caused this method to be called. | ||
*/ | ||
@Override | ||
public void processError(Throwable throwable) { | ||
System.out.println("Error while processing events"); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param closeReason {@link CloseReason} for closing this partition processor. | ||
* @return a representation of deferred initialization. | ||
*/ | ||
@Override | ||
public Mono<Void> close(CloseReason closeReason) { | ||
return Mono.empty(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.