Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kafka spy to check partitions #12

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions scripts/kafka_spy
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.option('--kafka-consumer-id', type=click.STRING, default='microservice', help='id of the kafka consumer, not really important')
@click.option('--kafka-consumer-group', type=click.STRING, default='kakfa-spy', help='group ID of the kafka consumer, very important to be unique or information will not be duplicated')
@click.option('--parse-as-json', type=click.BOOL, default=True, help='Tries to parse the messaage as a json')
@click.option('--only-partition-check', type=click.BOOL, default=False, help='Just returns the partition structure of the selected topics, then it dies')


def cli(kafka_address, kafka_port, kafka_topics, kafka_consumer_id, kafka_consumer_group, parse_as_json):

def cli(kafka_address, kafka_port, kafka_topics, kafka_consumer_id, kafka_consumer_group, parse_as_json, only_partition_check):

bootstrap = f"{kafka_address}:{kafka_port}"
print("From Kafka server:",bootstrap)
Expand All @@ -35,13 +37,21 @@ def cli(kafka_address, kafka_port, kafka_topics, kafka_consumer_id, kafka_consum
print("Consuming topics:", kafka_topics)
consumer.subscribe(kafka_topics)

for topic in kafka_topics :
partitions = consumer.partitions_for_topic(topic)
print( "Topic:", topic, "with", len(partitions), "partitions.")
for p in partitions :
print(p)

if (only_partition_check):
quit()

if parse_as_json :
print_json(consumer=consumer)
else:
print_string(consumer=consumer)



def print_string(consumer):
for message in consumer:
print("Key:", message.key)
Expand Down