MqttController.java 1.16 KB
package vion.controller.mqtt;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vion.dto.monitor.MqttAuthDTO;
import vion.service.monitor.IAgentService;

/**
 * 与 mqtt server 交互调用的接口
 */
@Slf4j
@RestController
@RequestMapping("/api/mqtt")
@RequiredArgsConstructor
public class MqttController {

    private final IAgentService agentService;

    @PostMapping("/auth")
    public ObjectNode auth(@RequestBody MqttAuthDTO dto) {
        return agentService.auth(dto);
    }

    @PostMapping("/webhook/connected")
    public void connected(@RequestBody JsonNode connectedInfo) {
        agentService.connected(connectedInfo);
    }

    @PostMapping("/webhook/disconnect")
    public void disconnect(@RequestBody JsonNode disconnectInfo) {
        agentService.disconnect(disconnectInfo);
    }

}