Skip to content

Commit ab161a3

Browse files
author
Ryan P
authored
Make group.id required for Consumer creation(confluentinc#472) (confluentinc#506)
1 parent 1a28d13 commit ab161a3

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

confluent_kafka/src/Consumer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,7 @@ static int Consumer_init (PyObject *selfobj, PyObject *args, PyObject *kwargs) {
13871387
rd_kafka_poll_set_consumer(self->rk);
13881388

13891389
self->u.Consumer.rkqu = rd_kafka_queue_get_consumer(self->rk);
1390+
assert(self->u.Consumer.rkqu);
13901391

13911392
return 0;
13921393
}
@@ -1423,8 +1424,8 @@ PyTypeObject ConsumerType = {
14231424
"\n"
14241425
".. py:function:: Consumer(config)\n"
14251426
"\n"
1426-
" :param dict config: Configuration properties. At a minimum ``bootstrap.servers`` and "
1427-
"``group.id`` **should** be set"
1427+
" :param dict config: Configuration properties. At a minimum ``group.id`` **must** be set,"
1428+
" ``bootstrap.servers`` **should** be set"
14281429
"\n"
14291430
"Create new Consumer instance using provided configuration dict.\n"
14301431
"\n"

confluent_kafka/src/confluent_kafka.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,15 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
16291629
PyDict_Update(confdict, kwargs);
16301630
}
16311631

1632+
if (ktype == RD_KAFKA_CONSUMER &&
1633+
!PyDict_GetItemString(confdict, "group.id")) {
1634+
1635+
PyErr_SetString(PyExc_ValueError,
1636+
"Failed to create consumer: group.id must be set");
1637+
Py_DECREF(confdict);
1638+
return NULL;
1639+
}
1640+
16321641
conf = rd_kafka_conf_new();
16331642

16341643
/*

tests/test_Consumer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,11 @@ def test_calling_store_offsets_after_close_throws_erro():
313313
with pytest.raises(RuntimeError) as ex:
314314
c.offsets_for_times([TopicPartition("test", 0)])
315315
assert 'Consumer closed' == str(ex.value)
316+
317+
318+
def test_consumer_withot_groupid():
319+
""" Consumer should raise exception if group.id is not set """
320+
321+
with pytest.raises(ValueError) as ex:
322+
Consumer({'bootstrap.servers': "mybroker:9092"})
323+
assert 'group.id must be set' in str(ex)

tests/test_misc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def test_unordered_dict(init_func):
155155
"""
156156
Interceptor configs can only be handled after the plugin has been loaded not before.
157157
"""
158-
client = init_func({'confluent.monitoring.interceptor.publishMs': 1000,
158+
client = init_func({'group.id': 'test-group',
159+
'confluent.monitoring.interceptor.publishMs': 1000,
159160
'confluent.monitoring.interceptor.sessionDurationMs': 1000,
160161
'plugin.library.paths': 'monitoring-interceptor',
161162
'confluent.monitoring.interceptor.topic': 'confluent-kafka-testing',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy