代码提交
This commit is contained in:
@@ -43,7 +43,4 @@ public class AccessController extends BaseController {
|
||||
accessService.add(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.pojo.MessageParam;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
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 javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/4/18 13:53
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
@Api(value = "TestController", tags = {"测试 API"})
|
||||
public class KafkaController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private KafkaTemplate<String, String> kafkaTemplate;
|
||||
|
||||
@PostMapping("/kafka/sendMessage")
|
||||
@ApiOperation(value = "发送kafka告警消息")
|
||||
public void sendKafkaMessage(@Valid @ApiParam("参数") @RequestBody MessageParam param) {
|
||||
kafkaTemplate.send(param.getTopic(), param.getMessage());
|
||||
}
|
||||
|
||||
@Component
|
||||
public class KafkaConsumer {
|
||||
// 消费监听
|
||||
@KafkaListener(topics = {"topic2"})
|
||||
public void onMessage1(ConsumerRecord<?, ?> record){
|
||||
// 消费的哪个topic、partition的消息,打印出消息内容
|
||||
System.out.println("简单消费:"+record.topic()+"-"+record.partition()+"-"+record.value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/5/12 10:28
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/topic")
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "装置主题")
|
||||
public class TopicController extends BaseController {
|
||||
|
||||
private final ICsTopicService csTopicService;
|
||||
|
||||
@PostMapping("/ask")
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("平台询问装置支持主题")
|
||||
@ApiImplicitParam(name = "nDid", value = "网关识别码", required = true)
|
||||
public HttpResult<Object> ask(@RequestParam String nDid){
|
||||
String methodDescribe = getMethodDescribe("ask");
|
||||
LogUtil.njcnDebug(log, "{},平台询问装置支持主题,请求的nDid为:{}", methodDescribe, nDid);
|
||||
csTopicService.askDevTopic(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user