Search in sources :

Example 1 with ConnectionStringBuilder

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);
}
Also used : ConnectionStringBuilder(com.microsoft.azure.eventhubs.ConnectionStringBuilder) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) EventHubException(com.microsoft.azure.eventhubs.EventHubException) IOException(java.io.IOException) SamzaException(org.apache.samza.SamzaException)

Example 2 with ConnectionStringBuilder

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));
    }
}
Also used : ConnectionStringBuilder(com.microsoft.azure.eventhubs.ConnectionStringBuilder) PartitionReceiver(com.microsoft.azure.eventhubs.PartitionReceiver) EventHubClient(com.microsoft.azure.eventhubs.EventHubClient) EventHubRuntimeInformation(com.microsoft.azure.eventhubs.EventHubRuntimeInformation)

Aggregations

ConnectionStringBuilder (com.microsoft.azure.eventhubs.ConnectionStringBuilder)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 EventHubClient (com.microsoft.azure.eventhubs.EventHubClient)1 EventHubException (com.microsoft.azure.eventhubs.EventHubException)1 EventHubRuntimeInformation (com.microsoft.azure.eventhubs.EventHubRuntimeInformation)1 PartitionReceiver (com.microsoft.azure.eventhubs.PartitionReceiver)1 IOException (java.io.IOException)1 SamzaException (org.apache.samza.SamzaException)1