package com.lutao.cloud.collect.kafka.producer;

import com.lutao.cloud.common.core.kafka.MessageTopicEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/message")
public class Producer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    /**
     * 发送消息模板
     */
    @GetMapping("/send")
    public void send(){
        String message = "你好，这是静态数据消息";
        // 第一个参数 topic
        // 第二个参数 消息
        ListenableFuture listenableFuture = kafkaTemplate.send(MessageTopicEnum.STATIC_DATA_ADD_TOPIC.getTopic(),message);
        System.out.println(listenableFuture);
    }

    @GetMapping("/send2")
    public void send2(){
        String message = "你好，这是动态数据消息";
        kafkaTemplate.send(MessageTopicEnum.DYNAMIC_DATA_UPDATE_TOPIC.getTopic(),message);
    }
}