use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class TridentKafkaState method updateState.
public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
String topic = null;
try {
List<Future<RecordMetadata>> futures = new ArrayList<>(tuples.size());
for (TridentTuple tuple : tuples) {
topic = topicSelector.getTopic(tuple);
if (topic != null) {
Future<RecordMetadata> result = producer.send(new ProducerRecord(topic, mapper.getKeyFromTuple(tuple), mapper.getMessageFromTuple(tuple)));
futures.add(result);
} else {
LOG.warn("skipping key = " + mapper.getKeyFromTuple(tuple) + ", topic selector returned null.");
}
}
List<ExecutionException> exceptions = new ArrayList<>(futures.size());
for (Future<RecordMetadata> future : futures) {
try {
future.get();
} catch (ExecutionException e) {
exceptions.add(e);
}
}
if (exceptions.size() > 0) {
String errorMsg = "Could not retrieve result for messages " + tuples + " from topic = " + topic + " because of the following exceptions: \n";
for (ExecutionException exception : exceptions) {
errorMsg = errorMsg + exception.getMessage() + "\n";
}
LOG.error(errorMsg);
throw new FailedException(errorMsg);
}
} catch (Exception ex) {
String errorMsg = "Could not send messages " + tuples + " to topic = " + topic;
LOG.warn(errorMsg, ex);
throw new FailedException(errorMsg, ex);
}
}
Aggregations