|
18 | 18 | # Example use of AdminClient operations.
|
19 | 19 |
|
20 | 20 | from confluent_kafka import (KafkaException, ConsumerGroupTopicPartitions,
|
21 |
| - TopicPartition, ConsumerGroupState, TopicCollection, |
22 |
| - IsolationLevel) |
| 21 | + TopicPartition, ConsumerGroupState, |
| 22 | + TopicCollection, IsolationLevel, |
| 23 | + ConsumerGroupType) |
23 | 24 | from confluent_kafka.admin import (AdminClient, NewTopic, NewPartitions, ConfigResource,
|
24 | 25 | ConfigEntry, ConfigSource, AclBinding,
|
25 | 26 | AclBindingFilter, ResourceType, ResourcePatternType,
|
@@ -471,18 +472,51 @@ def example_list(a, args):
|
471 | 472 | print("id {} client_id: {} client_host: {}".format(m.id, m.client_id, m.client_host))
|
472 | 473 |
|
473 | 474 |
|
| 475 | +def parse_list_consumer_groups_args(args, states, types): |
| 476 | + def usage(message): |
| 477 | + raise Exception(f"{message}\nUsage: list_consumer_groups [-states <state1> <state2> ..] " |
| 478 | + "[-types <type1> <type2> ..]") |
| 479 | + |
| 480 | + if len(args) > 0: |
| 481 | + typeArray = False |
| 482 | + stateArray = False |
| 483 | + lastArray = 0 |
| 484 | + for i in range(0, len(args)): |
| 485 | + if (args[i] == "-states"): |
| 486 | + if (stateArray): |
| 487 | + usage("Cannot pass the states flag (-states) more than once") |
| 488 | + lastArray = 1 |
| 489 | + stateArray = True |
| 490 | + elif (args[i] == "-types"): |
| 491 | + if (typeArray): |
| 492 | + usage("Cannot pass the types flag (-types) more than once") |
| 493 | + lastArray = 2 |
| 494 | + typeArray = True |
| 495 | + else: |
| 496 | + if (lastArray == 1): |
| 497 | + states.add(ConsumerGroupState[args[i]]) |
| 498 | + elif (lastArray == 2): |
| 499 | + types.add(ConsumerGroupType[args[i]]) |
| 500 | + else: |
| 501 | + usage(f"Unknown argument: {args[i]}") |
| 502 | + |
| 503 | + |
474 | 504 | def example_list_consumer_groups(a, args):
|
475 | 505 | """
|
476 | 506 | List Consumer Groups
|
477 | 507 | """
|
478 |
| - states = {ConsumerGroupState[state] for state in args} |
479 |
| - future = a.list_consumer_groups(request_timeout=10, states=states) |
| 508 | + |
| 509 | + states = set() |
| 510 | + types = set() |
| 511 | + parse_list_consumer_groups_args(args, states, types) |
| 512 | + |
| 513 | + future = a.list_consumer_groups(request_timeout=10, states=states, types=types) |
480 | 514 | try:
|
481 | 515 | list_consumer_groups_result = future.result()
|
482 | 516 | print("{} consumer groups".format(len(list_consumer_groups_result.valid)))
|
483 | 517 | for valid in list_consumer_groups_result.valid:
|
484 |
| - print(" id: {} is_simple: {} state: {}".format( |
485 |
| - valid.group_id, valid.is_simple_consumer_group, valid.state)) |
| 518 | + print(" id: {} is_simple: {} state: {} type: {}".format( |
| 519 | + valid.group_id, valid.is_simple_consumer_group, valid.state, valid.type)) |
486 | 520 | print("{} errors".format(len(list_consumer_groups_result.errors)))
|
487 | 521 | for error in list_consumer_groups_result.errors:
|
488 | 522 | print(" error: {}".format(error))
|
|
0 commit comments