from confluent_kafka import Producer
from .setup import config

producer = Producer(**config)  # NB needs to moved


def acked(err, msg):
    # NB needs to be updated and logged.
    if err is not None:
        print(f"Failed to deliver message: {err.str()}")
    else:
        print(f"Message published successfully")


def publish_message(topic, value, key):
    producer.produce(topic, key=key, value=value, callback=acked)
    producer.flush()  # NB needs to moved
    return "Message published"
