[
https://issues.apache.org/jira/browse/NIFI-2608?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15433772#comment-15433772
]
Joseph Witt commented on NIFI-2608:
-----------------------------------
Status of this work:
* Not ready to submit a PR but the evolving work is here
https://github.com/joewitt/incubator-nifi/commits/NIFI-2608
* Changes made so far:
** now uses a ConsumerPool to encapsulate the KafkaConsumer and to ensure
multi-threaded access to the pool ensures only a single KafkaConsumer is used
by a single thread at a time. The ConsumerPool returns ConsumerLeases and that
supports all necessary calls for interaction with the true kafka api (poll,
commitOffsets).
** ConsumeKafka reworked to use the ConsumerPool exclusively and supports easy
mocking of the ConsumerPool to ensure unit testing focuses on the processor and
its behavior rather than the kafka client. Several benefits came from this
approach:
*** We support multiple topic pulling now via a comma separated list of topics.
*** We ensure data when being merged into flowFiles is merged in a manner that
maintains its topic/partion/offset ordering and grouping and ensures the first
offset is stored with the flow file and we don't store the key for groups since
the key wouldn't be meaningful.
*** The ConsumerPool and usage logic makes reasoning over handling of consumers
very straightforward and in the event of an exception using a consumer its
lease can be poisoned thus ensuring it will be actually closed and a new one
made.
*** Using an easy to reason over try w/resources approach to handling
ConsumerLeases from the pool.
*** We ensure the offsets for all topics and partitions are accounted for and
committed once all items are written to the session and committed to the
session.
** The key of a kafka message is now being hex encoded and is called
'kafka.key.hex'. This means it can be used by PublishKafka or others without
worrying about it having been improperly interpreted into UTF-8 or something
else. Its raw byte value is thus maintained.
Work that remains:
* Fix tests for producer after moving code.
* Update WritesAttributes annotations for ConsumeKafka to account for all items
* Consider providing Consume and Publish Kafka processors for the 0.10 API.
While the API is the same there is apparently a way to limit how many messages
come back from Kafka as a result of a single poll call which we definitely want
to use. Also, while the 0.9 clients can talk to 0.10 brokers the Kafka docs
indicate there may be a steep kafka server/broker performance penalty due to
changes in how the compaction or compression mechanism works. Could call these
processors ConsumeKafka010 and PublishKafka010.
> Thread-safety issue with ConsumeKafka
> -------------------------------------
>
> Key: NIFI-2608
> URL: https://issues.apache.org/jira/browse/NIFI-2608
> Project: Apache NiFi
> Issue Type: Bug
> Reporter: Oleg Zhurakousky
> Assignee: Joseph Witt
> Fix For: 1.0.0
>
>
> KafkaConsumer went fro thread-safe in 0.8 to not-thread-safe in 0.9 which was
> overlooked while implementing new ConsumeKafka processor which relied on 0.9
> Client API.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)