Java Code Examples for com.microsoft.azure.eventhubs.EventHubClient#createReceiverSync()
The following examples show how to use
com.microsoft.azure.eventhubs.EventHubClient#createReceiverSync() .
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: ITestEventHubSystemProducer.java From samza with Apache License 2.0 | 5 votes |
@Test public void testReceive() throws EventHubException { EventHubClientManagerFactory clientFactory = new EventHubClientManagerFactory(); EventHubClientManager wrapper = clientFactory .getEventHubClientManager(SYSTEM_NAME, STREAM_NAME1, new EventHubConfig(createEventHubConfig())); wrapper.init(); EventHubClient client = wrapper.getEventHubClient(); PartitionReceiver receiver = client.createReceiverSync(EventHubClient.DEFAULT_CONSUMER_GROUP_NAME, "0", EventPosition.fromStartOfStream()); receiveMessages(receiver, 300); }