package com.viettel.campaign.web.rest;

import com.viettel.campaign.service.Sender;
import com.viettel.campaign.service.Producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hanv_itsol
 * @project service-campaign
 */
@Slf4j
@RestController
@RequestMapping(value = "/kafka")
public class KafkaController {

    private final Sender sender;

    private final Producer producer;

    @Autowired
    KafkaController(Sender sender, Producer producer) {
        this.sender = sender;
        this.producer = producer;
    }

    @PostMapping(value = "/publish")
    public void sendMessageToKafkaTopic(@RequestParam("message") String message) {
        log.info("message: " + message);
        this.producer.sendMessage(message);
    }

    @PostMapping(value = "/publish2")
    public void sendMessageToKafkaTopic2(@RequestParam("message") String message) {
        log.info("message: " + message);
        this.producer.sendMessageTopic2(message);
    }

    @GetMapping(value = "/test")
    public void test(){
        sender.send("hanv", "haha");
    }
}
