|
@@ -2,17 +2,20 @@ package com.crossoverjie.netty.action.client.controller; |
|
@@ -2,17 +2,20 @@ package com.crossoverjie.netty.action.client.controller; |
|
2
|
|
2
|
|
|
3
|
import com.crossoverjie.netty.action.client.HeartbeatClient;
|
3
|
import com.crossoverjie.netty.action.client.HeartbeatClient;
|
|
4
|
import com.crossoverjie.netty.action.client.vo.req.SendMsgReqVO;
|
4
|
import com.crossoverjie.netty.action.client.vo.req.SendMsgReqVO;
|
|
|
|
5
|
+import com.crossoverjie.netty.action.client.vo.req.StringReqVO;
|
|
5
|
import com.crossoverjie.netty.action.client.vo.res.SendMsgResVO;
|
6
|
import com.crossoverjie.netty.action.client.vo.res.SendMsgResVO;
|
|
6
|
import com.crossoverjie.netty.action.common.constant.Constants;
|
7
|
import com.crossoverjie.netty.action.common.constant.Constants;
|
|
7
|
import com.crossoverjie.netty.action.common.enums.StatusEnum;
|
8
|
import com.crossoverjie.netty.action.common.enums.StatusEnum;
|
|
8
|
import com.crossoverjie.netty.action.common.pojo.CustomProtocol;
|
9
|
import com.crossoverjie.netty.action.common.pojo.CustomProtocol;
|
|
9
|
import com.crossoverjie.netty.action.common.res.BaseResponse;
|
10
|
import com.crossoverjie.netty.action.common.res.BaseResponse;
|
|
|
|
11
|
+import com.crossoverjie.netty.action.common.res.NULLBody;
|
|
10
|
import io.swagger.annotations.ApiOperation;
|
12
|
import io.swagger.annotations.ApiOperation;
|
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
12
|
import org.springframework.boot.actuate.metrics.CounterService;
|
14
|
import org.springframework.boot.actuate.metrics.CounterService;
|
|
13
|
import org.springframework.stereotype.Controller;
|
15
|
import org.springframework.stereotype.Controller;
|
|
14
|
import org.springframework.web.bind.annotation.RequestBody;
|
16
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
15
|
import org.springframework.web.bind.annotation.RequestMapping;
|
17
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
18
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
16
|
import org.springframework.web.bind.annotation.ResponseBody;
|
19
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
17
|
|
20
|
|
|
18
|
/**
|
21
|
/**
|
|
@@ -41,8 +44,8 @@ public class IndexController { |
|
@@ -41,8 +44,8 @@ public class IndexController { |
|
41
|
* @return
|
44
|
* @return
|
|
42
|
*/
|
45
|
*/
|
|
43
|
@ApiOperation("客户端发送消息")
|
46
|
@ApiOperation("客户端发送消息")
|
|
44
|
- @RequestMapping("sendMsg")
|
|
|
|
45
|
- @ResponseBody
|
47
|
+ @RequestMapping(value = "sendMsg",method = RequestMethod.POST)
|
|
|
|
48
|
+ @ResponseBody()
|
|
46
|
public BaseResponse<SendMsgResVO> sendMsg(@RequestBody SendMsgReqVO sendMsgReqVO){
|
49
|
public BaseResponse<SendMsgResVO> sendMsg(@RequestBody SendMsgReqVO sendMsgReqVO){
|
|
47
|
BaseResponse<SendMsgResVO> res = new BaseResponse();
|
50
|
BaseResponse<SendMsgResVO> res = new BaseResponse();
|
|
48
|
heartbeatClient.sendMsg(new CustomProtocol(sendMsgReqVO.getId(),sendMsgReqVO.getMsg())) ;
|
51
|
heartbeatClient.sendMsg(new CustomProtocol(sendMsgReqVO.getId(),sendMsgReqVO.getMsg())) ;
|
|
@@ -60,15 +63,15 @@ public class IndexController { |
|
@@ -60,15 +63,15 @@ public class IndexController { |
|
60
|
|
63
|
|
|
61
|
/**
|
64
|
/**
|
|
62
|
* 向服务端发消息 字符串
|
65
|
* 向服务端发消息 字符串
|
|
63
|
- * @param msg
|
66
|
+ * @param stringReqVO
|
|
64
|
* @return
|
67
|
* @return
|
|
65
|
*/
|
68
|
*/
|
|
66
|
@ApiOperation("客户端发送消息,字符串")
|
69
|
@ApiOperation("客户端发送消息,字符串")
|
|
67
|
- @RequestMapping("sendStringMsg")
|
70
|
+ @RequestMapping(value = "sendStringMsg", method = RequestMethod.POST)
|
|
68
|
@ResponseBody
|
71
|
@ResponseBody
|
|
69
|
- public BaseResponse<SendMsgResVO> sendStringMsg(@RequestBody String msg){
|
|
|
|
70
|
- BaseResponse<SendMsgResVO> res = new BaseResponse();
|
|
|
|
71
|
- heartbeatClient.sendStringMsg(msg) ;
|
72
|
+ public BaseResponse<NULLBody> sendStringMsg(@RequestBody StringReqVO stringReqVO){
|
|
|
|
73
|
+ BaseResponse<NULLBody> res = new BaseResponse();
|
|
|
|
74
|
+ heartbeatClient.sendStringMsg(stringReqVO.getMsg()) ;
|
|
72
|
|
75
|
|
|
73
|
// 利用 actuator 来自增
|
76
|
// 利用 actuator 来自增
|
|
74
|
counterService.increment(Constants.COUNTER_CLIENT_PUSH_COUNT);
|
77
|
counterService.increment(Constants.COUNTER_CLIENT_PUSH_COUNT);
|
|
@@ -77,7 +80,6 @@ public class IndexController { |
|
@@ -77,7 +80,6 @@ public class IndexController { |
|
77
|
sendMsgResVO.setMsg("OK") ;
|
80
|
sendMsgResVO.setMsg("OK") ;
|
|
78
|
res.setCode(StatusEnum.SUCCESS.getCode()) ;
|
81
|
res.setCode(StatusEnum.SUCCESS.getCode()) ;
|
|
79
|
res.setMessage(StatusEnum.SUCCESS.getMessage()) ;
|
82
|
res.setMessage(StatusEnum.SUCCESS.getMessage()) ;
|
|
80
|
- res.setDataBody(sendMsgResVO) ;
|
|
|
|
81
|
return res ;
|
83
|
return res ;
|
|
82
|
}
|
84
|
}
|
|
83
|
} |
85
|
} |