package com.itheima.kafka.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.kafka.core.KafkaTemplate;

/**
 * Kafka生产者启动类
 */
@SpringBootApplication
public class KafkaProducerApplication {

    // 定义日志记录器
    private static final Logger LOGGER = LoggerFactory.getLogger(KafkaProducerApplication.class) ;

    // 定义发送消息的模板类
    private static KafkaTemplate kafkaTemplate ;

    public static void main(String[] args) {

        // 初始化环境
        ConfigurableApplicationContext applicationContext = SpringApplication.run(KafkaProducerApplication.class, args);
        kafkaTemplate = applicationContext.getBean(KafkaTemplate.class) ;

        // 测试Kafka环境
        environmentTest();
    }

    // Kafka单节点环境测试
    public static void environmentTest(){
        kafkaTemplate.send("itheima" , "Kakfa环境测试....") ;
    }

}
