/*
package com.muyu.carData.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

*/
/**
 * @Author：张腾
 * @Package：com.muyu.carData.testcontroller
 * @Project：cloud-server-8
 * @name：KafkaProducerController
 * @Date：2024/9/28 15:10
 *//*

@RestController
@RequestMapping("/produce")
@Log4j2
public class KafkaProducerController {

    @Autowired
    private KafkaProducer kafkaProducer;

    private final String topicName = "carJsons";

    @GetMapping("/producer")
    public String produceTest(JSONObject data) {
        try {
            log.info("Topic:{}", topicName);
            log.info("转换为JSON：{}",data);
            //使用KafkaProducer发送消息
            ProducerRecord<String, String> stringProducerRecord = new ProducerRecord(topicName, data);
            kafkaProducer.send(stringProducerRecord);
        }catch (Exception e){
            log.error("Producer写入Topic异常,异常信息是：{}",e.getMessage());
        }
        return "消息发送成功";
    }



}
*/
