use of com.microsoft.azure.eventhubs.EventHubException in project samza by apache.
the class EventHubSystemProducer method init.
private void init() {
LOG.info("Initializing EventHubSystemProducer");
// Fetches the stream ids
List<String> streamIds = config.getStreams(systemName);
// partition count)
for (String streamId : streamIds) {
EventHubClientManager ehClient = eventHubClientManagerFactory.getEventHubClientManager(systemName, streamId, config);
perStreamEventHubClientManagers.put(streamId, ehClient);
ehClient.init();
}
// Create partition senders if required
if (PartitioningMethod.PARTITION_KEY_AS_PARTITION.equals(partitioningMethod)) {
// Create all partition senders
perStreamEventHubClientManagers.forEach((streamId, samzaEventHubClient) -> {
EventHubClient ehClient = samzaEventHubClient.getEventHubClient();
try {
Map<Integer, PartitionSender> partitionSenders = new HashMap<>();
long timeoutMs = config.getRuntimeInfoWaitTimeMS(systemName);
Integer numPartitions = ehClient.getRuntimeInformation().get(timeoutMs, TimeUnit.MILLISECONDS).getPartitionCount();
for (int i = 0; i < numPartitions; i++) {
String partitionId = String.valueOf(i);
EventHubClientManager perPartitionClientManager = createOrGetEventHubClientManagerForPartition(streamId, i);
PartitionSender partitionSender = perPartitionClientManager.getEventHubClient().createPartitionSender(partitionId).get(DEFAULT_CREATE_PARTITION_SENDER_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
partitionSenders.put(i, partitionSender);
}
streamPartitionSenders.put(streamId, partitionSenders);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
String msg = "Failed to fetch number of Event Hub partitions for partition sender creation";
throw new SamzaException(msg, e);
} catch (EventHubException | IllegalArgumentException e) {
String msg = "Creation of partition sender failed with exception";
throw new SamzaException(msg, e);
}
});
}
isInitialized = true;
LOG.info("EventHubSystemProducer initialized.");
}
use of com.microsoft.azure.eventhubs.EventHubException 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.EventHubException in project samza by apache.
the class EventHubConsoleConsumer method main.
public static void main(String[] args) throws EventHubException, IOException, ExecutionException, InterruptedException {
Options options = new Options();
options.addOption(CommandLineHelper.createOption(OPT_SHORT_EVENTHUB_NAME, OPT_LONG_EVENTHUB_NAME, OPT_ARG_EVENTHUB_NAME, true, OPT_DESC_EVENTHUB_NAME));
options.addOption(CommandLineHelper.createOption(OPT_SHORT_NAMESPACE, OPT_LONG_NAMESPACE, OPT_ARG_NAMESPACE, true, OPT_DESC_NAMESPACE));
options.addOption(CommandLineHelper.createOption(OPT_SHORT_KEY_NAME, OPT_LONG_KEY_NAME, OPT_ARG_KEY_NAME, true, OPT_DESC_KEY_NAME));
options.addOption(CommandLineHelper.createOption(OPT_SHORT_TOKEN, OPT_LONG_TOKEN, OPT_ARG_TOKEN, true, OPT_DESC_TOKEN));
CommandLineParser parser = new BasicParser();
CommandLine cmd;
try {
cmd = parser.parse(options, args);
} catch (Exception e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(String.format("Error: %s%neh-console-consumer.sh", e.getMessage()), options);
return;
}
String ehName = cmd.getOptionValue(OPT_SHORT_EVENTHUB_NAME);
String namespace = cmd.getOptionValue(OPT_SHORT_NAMESPACE);
String keyName = cmd.getOptionValue(OPT_SHORT_KEY_NAME);
String token = cmd.getOptionValue(OPT_SHORT_TOKEN);
consumeEvents(ehName, namespace, keyName, token);
}
Aggregations