NIFI-220: Added error handling that was missing for one instance of calling producer.send, also indicated how many messages were sent per FlowFile in log message and provenance event

This commit is contained in:
Mark Payne 2015-01-13 19:27:07 -05:00
parent 95b22a0aee
commit a77fb50116
1 changed files with 16 additions and 12 deletions

View File

@ -366,7 +366,11 @@ public class PutKafka extends AbstractProcessor {
// If there are messages left, send them // If there are messages left, send them
if ( !messages.isEmpty() ) { if ( !messages.isEmpty() ) {
try {
producer.send(messages); producer.send(messages);
} catch (final Exception e) {
throw new ProcessException("Failed to send messages to Kafka", e);
}
} }
} }
} }
@ -374,9 +378,9 @@ public class PutKafka extends AbstractProcessor {
final long nanos = System.nanoTime() - start; final long nanos = System.nanoTime() - start;
session.getProvenanceReporter().send(flowFile, "kafka://" + topic); session.getProvenanceReporter().send(flowFile, "kafka://" + topic, "Sent " + messagesSent.get() + " messages");
session.transfer(flowFile, REL_SUCCESS); session.transfer(flowFile, REL_SUCCESS);
getLogger().info("Successfully sent {} to Kafka in {} millis", new Object[] {flowFile, TimeUnit.NANOSECONDS.toMillis(nanos)}); getLogger().info("Successfully sent {} messages to Kafka for {} in {} millis", new Object[] {messagesSent.get(), flowFile, TimeUnit.NANOSECONDS.toMillis(nanos)});
} catch (final ProcessException pe) { } catch (final ProcessException pe) {
error = true; error = true;