Skip to content

Commit fb60d42

Browse files
committed
BREAKING CHANGE: Replacing host & port by bootstrap_servers
feat: Add client_id to consumer
1 parent 6cdd8dc commit fb60d42

File tree

9 files changed

+28
-29
lines changed

9 files changed

+28
-29
lines changed

extensions/eda/plugins/event_source/kafka.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
description:
1414
- An ansible-rulebook event source plugin for receiving events via a kafka topic.
1515
options:
16-
host:
16+
bootstrap_servers:
1717
description:
18-
- The host where the kafka topic is hosted.
19-
type: str
20-
required: true
21-
port:
22-
description:
23-
- The port where the kafka server is listening.
24-
type: str
18+
- A host[:port] string (or list of host[:port] strings)
19+
that the consumer should contact to bootstrap initial cluster metadata.
20+
This does not have to be the full node list.
21+
It just needs to have at least one broker that will respond to a Metadata API Request
22+
type: str,list(str)
2523
required: true
2624
cafile:
2725
description:
@@ -87,6 +85,14 @@
8785
- A kafka group id.
8886
type: str
8987
default: null
88+
client_id:
89+
description:
90+
- client_id (str) – a name for this client.
91+
This string is passed in each request to servers and can be used to identify specific server-side log entries
92+
that correspond to this client.
93+
Also submitted to GroupCoordinator for logging with respect to consumer group administration
94+
type: str
95+
default: null
9096
offset:
9197
description:
9298
- Where to automatically reset the offset.
@@ -125,15 +131,15 @@
125131

126132
EXAMPLES = r"""
127133
- ansible.eda.kafka:
128-
host: "localhost"
129-
port: "9092"
134+
bootstrap_servers: broker-1:9092,broker-2:9093:broker-3:9094
130135
check_hostname: true
131136
verify_mode: "CERT_OPTIONAL"
132137
encoding: "utf-8"
133138
topics:
134139
- "demo"
135140
- "demo2"
136141
group_id: "test"
142+
client_id: "client-01"
137143
offset: "earliest"
138144
security_protocol: "SASL_PLAINTEXT"
139145
sasl_mechanism: "GSSAPI"
@@ -161,15 +167,15 @@ async def main( # pylint: disable=R0914
161167
if topic:
162168
topics = [topic]
163169

164-
host = args.get("host")
165-
port = args.get("port")
170+
bootstrap_servers = args.get("bootstrap_servers")
166171
cafile = args.get("cafile")
167172
certfile = args.get("certfile")
168173
keyfile = args.get("keyfile")
169174
password = args.get("password")
170175
check_hostname = args.get("check_hostname", True)
171176
verify_mode = args.get("verify_mode", "CERT_REQUIRED")
172177
group_id = args.get("group_id")
178+
client_id = args.get("client_id", "")
173179
offset = args.get("offset", "latest")
174180
encoding = args.get("encoding", "utf-8")
175181
security_protocol = args.get("security_protocol", "PLAINTEXT")
@@ -202,8 +208,9 @@ async def main( # pylint: disable=R0914
202208
ssl_context.verify_mode = verify_mode
203209

204210
kafka_consumer = AIOKafkaConsumer(
205-
bootstrap_servers=f"{host}:{port}",
211+
bootstrap_servers=bootstrap_servers,
206212
group_id=group_id,
213+
client_id=client_id,
207214
enable_auto_commit=True,
208215
max_poll_records=1,
209216
auto_offset_reset=offset,

tests/integration/event_source_kafka/test_kafka_rules_headers.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
sources:
44
- ansible.eda.kafka:
55
topic: kafka-events-plaintext
6-
host: localhost
7-
port: 9092
6+
bootstrap_servers: localhost:9092
87
offset: earliest
98
encoding: ascii
109
rules:

tests/integration/event_source_kafka/test_kafka_rules_multiple_topics.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
topics:
66
- kafka-events-topic1
77
- kafka-events-topic2
8-
host: localhost
9-
port: 9092
8+
bootstrap_servers: localhost:9092
109
offset: earliest
1110
encoding: ascii
1211
rules:

tests/integration/event_source_kafka/test_kafka_rules_pattern_topics.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
sources:
44
- ansible.eda.kafka:
55
topic_pattern: "kafka-pattern-.*"
6-
host: localhost
7-
port: 9092
6+
bootstrap_servers: localhost:9092
87
offset: earliest
98
encoding: ascii
109
rules:

tests/integration/event_source_kafka/test_kafka_rules_plaintext.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
sources:
44
- ansible.eda.kafka:
55
topic: kafka-events-plaintext
6-
host: localhost
7-
port: 9092
6+
bootstrap_servers: localhost:9092
87
offset: earliest
98
encoding: ascii
109
rules:

tests/integration/event_source_kafka/test_kafka_rules_sasl_plaintext.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
sources:
44
- ansible.eda.kafka:
55
topic: kafka-events-sasl-plaintext
6-
host: localhost
7-
port: 9094
6+
bootstrap_servers: localhost:9094
87
offset: earliest
98
encoding: ascii
109
security_protocol: SASL_PLAINTEXT

tests/integration/event_source_kafka/test_kafka_rules_sasl_ssl.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
sources:
44
- ansible.eda.kafka:
55
topic: kafka-events-sasl-ssl
6-
host: localhost
7-
port: 9095
6+
bootstrap_servers: localhost:9095
87
offset: earliest
98
encoding: ascii
109
security_protocol: SASL_SSL

tests/integration/event_source_kafka/test_kafka_rules_ssl.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
sources:
44
- ansible.eda.kafka:
55
topic: kafka-events-ssl
6-
host: localhost
7-
port: 9093
6+
bootstrap_servers: localhost:9093
87
offset: earliest
98
encoding: ascii
109
security_protocol: SSL

tests/unit/event_source/test_kafka.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def test_receive_from_kafka_place_in_queue(
6666
myqueue,
6767
{
6868
topic_type: topic_value,
69-
"host": "localhost",
70-
"port": "9092",
69+
"bootstrap_servers": "localhost:9092",
7170
"group_id": "test",
7271
},
7372
)

0 commit comments

Comments
 (0)