toString() on KafkaStream gets stuck indefinitely

Details

Description

There is no toString implementation for KafkaStream, so if a user tries to print the stream it falls back to default toString implementation which tries to iterate over the collection and gets stuck indefinitely as it awaits messages. KafkaStream could instead override the toString and return a verbose description of the stream with topic name etc.

Activity

Yes this is due to KafkaStream being a scala iterable - toString on
an iterable (per the scala-doc): "returns a string representation of
this collection. By default this string consists of the stringPrefix
of this immutable iterable collection, followed by all elements
separated by commas and enclosed in parentheses."
We can just override it simce others have run into this as well.

Joel Koshy
added a comment - 26/Nov/13 19:57 Yes this is due to KafkaStream being a scala iterable - toString on
an iterable (per the scala-doc): "returns a string representation of
this collection. By default this string consists of the stringPrefix
of this immutable iterable collection, followed by all elements
separated by commas and enclosed in parentheses."
We can just override it simce others have run into this as well.

We could just print something like "%s kafka stream".format(clientId) - there's very little information that the KafkaStream class exposes. However, this is more to protect against iterating over the full stream on a toString call. toString on KafkaStream does not really make sense - so even a message to that effect should be fine.

Joel Koshy
added a comment - 27/Nov/13 20:33 We could just print something like "%s kafka stream".format(clientId) - there's very little information that the KafkaStream class exposes. However, this is more to protect against iterating over the full stream on a toString call. toString on KafkaStream does not really make sense - so even a message to that effect should be fine.