use of com.microsoft.azure.eventhubs.ConnectionStringBuilder in project samza by apache.
the class SamzaEventHubClientManager method init.
@Override
public void init() {
String remoteHost = String.format(EVENTHUB_REMOTE_HOST_FORMAT, eventHubNamespace);
LOG.info("Initializing SamzaEventHubClientManager for namespace: " + eventHubNamespace);
try {
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder().setNamespaceName(eventHubNamespace).setEventHubName(entityPath).setSasKeyName(sasKeyName).setSasKey(sasKey);
ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder().setNameFormat("Samza EventHubClient Thread-%d").setDaemon(true);
eventHubClientExecutor = Executors.newFixedThreadPool(numClientThreads, threadFactoryBuilder.build());
eventHubClient = EventHubClient.createSync(connectionStringBuilder.toString(), retryPolicy, eventHubClientExecutor);
} catch (IOException | EventHubException e) {
String msg = String.format("Creation of EventHub client failed for eventHub EntityPath: %s on remote host %s:%d", entityPath, remoteHost, ClientConstants.AMQPS_PORT);
LOG.error(msg, e);
throw new SamzaException(msg, e);
}
LOG.info("SamzaEventHubClientManager initialized for namespace: " + eventHubNamespace);
}
use of com.microsoft.azure.eventhubs.ConnectionStringBuilder in project samza by apache.
the class EventHubConsoleConsumer method consumeEvents.
private static void consumeEvents(String ehName, String namespace, String keyName, String token) throws EventHubException, IOException, ExecutionException, InterruptedException {
ConnectionStringBuilder connStr = new ConnectionStringBuilder().setNamespaceName(namespace).setEventHubName(ehName).setSasKeyName(keyName).setSasKey(token);
EventHubClient client = EventHubClient.createSync(connStr.toString(), Executors.newFixedThreadPool(10));
EventHubRuntimeInformation runTimeInfo = client.getRuntimeInformation().get();
int numPartitions = runTimeInfo.getPartitionCount();
for (int partition = 0; partition < numPartitions; partition++) {
PartitionReceiver receiver = client.createReceiverSync(EventHubClient.DEFAULT_CONSUMER_GROUP_NAME, String.valueOf(partition), EventPosition.fromStartOfStream());
receiver.receive(10).handle((records, throwable) -> handleComplete(receiver, records, throwable));
}
}
Aggregations