Java Code Examples for com.microsoft.azure.eventhubs.EventHubClient#createSync()
The following examples show how to use
com.microsoft.azure.eventhubs.EventHubClient#createSync() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventHubConsoleConsumer.java From samza with Apache License 2.0 | 6 votes |
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)); } }
Example 2
Source File: SamzaEventHubClientManager.java From samza with Apache License 2.0 | 6 votes |
@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); }
Example 3
Source File: EventHubCommon.java From datacollector with Apache License 2.0 | 5 votes |
public EventHubClient createEventHubClient(String threadNamePattern) throws IOException, EventHubException { final ConnectionStringBuilder connStr = new ConnectionStringBuilder() .setNamespaceName(commonConf.namespaceName) .setEventHubName(commonConf.eventHubName) .setSasKey(commonConf.sasKey.get()) .setSasKeyName(commonConf.sasKeyName); final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat(threadNamePattern).build() ); return EventHubClient.createSync(connStr.toString(), scheduledExecutorService); }
Example 4
Source File: AzureIoTService.java From para with Apache License 2.0 | 5 votes |
private static EventHubClient receiveEventsAsync(final String partitionId) { EventHubClient client = null; try { client = EventHubClient.createSync(EVENTHUB_CONN_STR, Para.getExecutorService()); client.createReceiver(EventHubClient.DEFAULT_CONSUMER_GROUP_NAME, partitionId, EventPosition.fromEnqueuedTime(Instant.now())). thenAccept(new Receiver(partitionId)); } catch (Exception e) { logger.warn("Couldn't start receiving messages from Azure cloud: {}", e.getMessage()); } return client; }