-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
1 parent
b651d78
commit c876a6e
Showing
69 changed files
with
1,814 additions
and
584 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
94 changes: 94 additions & 0 deletions
94
...thubs-eph/src/main/java/com/microsoft/azure/eventprocessorhost/EventHubClientFactory.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,94 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.azure.eventprocessorhost; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
import com.microsoft.azure.eventhubs.AzureActiveDirectoryTokenProvider; | ||
import com.microsoft.azure.eventhubs.EventHubClient; | ||
import com.microsoft.azure.eventhubs.EventHubClientOptions; | ||
import com.microsoft.azure.eventhubs.EventHubException; | ||
import com.microsoft.azure.eventhubs.ITokenProvider; | ||
import com.microsoft.azure.eventhubs.RetryPolicy; | ||
|
||
abstract class EventHubClientFactory { | ||
protected ScheduledExecutorService executor; | ||
|
||
protected final EventHubClientOptions options; | ||
|
||
public EventHubClientFactory(final RetryPolicy retryPolicy) { | ||
this((new EventHubClientOptions()).setRetryPolicy(retryPolicy)); | ||
} | ||
|
||
public EventHubClientFactory(final EventHubClientOptions options) { | ||
this.options = options; | ||
} | ||
|
||
public void setExecutor(ScheduledExecutorService executor) { | ||
this.executor = executor; | ||
} | ||
|
||
abstract CompletableFuture<EventHubClient> createEventHubClient() throws EventHubException, IOException; | ||
|
||
static class EHCFWithConnectionString extends EventHubClientFactory { | ||
private final String eventHubConnectionString; | ||
|
||
public EHCFWithConnectionString(final String eventHubConnectionString, | ||
final RetryPolicy retryPolicy) { | ||
super(retryPolicy); | ||
this.eventHubConnectionString = eventHubConnectionString; | ||
} | ||
|
||
public CompletableFuture<EventHubClient> createEventHubClient() throws EventHubException, IOException { | ||
return EventHubClient.createFromConnectionString(this.eventHubConnectionString, this.options.getRetryPolicy(), this.executor); | ||
} | ||
} | ||
|
||
static class EHCFWithAuthCallback extends EventHubClientFactory { | ||
private final URI endpoint; | ||
private final String eventHubPath; | ||
private final AzureActiveDirectoryTokenProvider.AuthenticationCallback authCallback; | ||
private final String authority; | ||
|
||
public EHCFWithAuthCallback(final URI endpoint, | ||
final String eventHubPath, | ||
final AzureActiveDirectoryTokenProvider.AuthenticationCallback authCallback, | ||
final String authority, | ||
final EventHubClientOptions options) { | ||
super(options); | ||
this.endpoint = endpoint; | ||
this.eventHubPath = eventHubPath; | ||
this.authCallback = authCallback; | ||
this.authority = authority; | ||
} | ||
|
||
public CompletableFuture<EventHubClient> createEventHubClient() throws EventHubException, IOException { | ||
return EventHubClient.createWithAzureActiveDirectory(this.endpoint, | ||
this.eventHubPath, this.authCallback, this.authority, this.executor, this.options); | ||
} | ||
} | ||
|
||
static class EHCFWithTokenProvider extends EventHubClientFactory { | ||
private final URI endpoint; | ||
private final String eventHubPath; | ||
private final ITokenProvider tokenProvider; | ||
|
||
public EHCFWithTokenProvider(final URI endpoint, | ||
final String eventHubPath, | ||
final ITokenProvider tokenProvider, | ||
final EventHubClientOptions options) { | ||
super(options); | ||
this.endpoint = endpoint; | ||
this.eventHubPath = eventHubPath; | ||
this.tokenProvider = tokenProvider; | ||
} | ||
|
||
public CompletableFuture<EventHubClient> createEventHubClient() throws EventHubException, IOException { | ||
return EventHubClient.createWithTokenProvider(this.endpoint, this.eventHubPath, this.tokenProvider, this.executor, this.options); | ||
} | ||
} | ||
} |
Oops, something went wrong.