package com.example.kafka.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * Message producer class to produce messages into kafka topic
 */
@Component("/msgProducer")
public class MessageProducer {

    private static final Logger log = LoggerFactory.getLogger(MessageProducer.class.getName());

    @Autowired
    KafkaTemplate<String, String> template;

    @Value("${app.topic.name}")
    private String topicName;

    /**
     * Publish the order to kafka topic
     * @param order The order
     */
    public void publishOrder(String order){
        template.send(topicName,order);
        log.info("published order {} ::",order);
    }
}
