Include Kafka Message Key in Events
butschi84 opened this issue · 0 comments
butschi84 commented
I suggest to include the "message key" (from the events in the kafka message queue) in the event that is being put into the event-driven-ansible queue because it can be very useful when filtering for certain events in an ansible-rulebook.
Therefore this file would have to be changed:
extensions/eda/plugins/event_sources/kafka.py
to something like:
async for msg in kafka_consumer:
try:
data = json.loads(msg.value)
data["key"] = msg.key.decode('utf-8')
await queue.put(data)
...
After this change i can listen for events with certain key in the rulebook:
- name: listen kafka
hosts: all
sources:
- ansible.eda.kafka:
host: 7.7.7.7
port: 30051
topic: my-topic
group_id: ansible-eda
rules:
- name: kafka
condition: event.key == "test-0"
action:
run_playbook:
name: do-something.yml