[RPC] 增加订阅支持
This commit is contained in:
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.service.redisMsg;
|
||||
import com.genersoft.iot.vmp.common.CommonCallback;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo;
|
||||
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
|
||||
public interface IRedisRpcService {
|
||||
@@ -24,4 +25,7 @@ public interface IRedisRpcService {
|
||||
long onStreamOnlineEvent(String app, String stream, CommonCallback<StreamInfo> callback);
|
||||
void unPushStreamOnlineEvent(String app, String stream);
|
||||
|
||||
void subscribeCatalog(int id, int cycle);
|
||||
|
||||
void subscribeMobilePosition(int id, int cycle, int interval);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.genersoft.iot.vmp.service.redisMsg.control;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.redis.RedisRpcConfig;
|
||||
import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcMessage;
|
||||
import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcRequest;
|
||||
import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcResponse;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.InviteMessageInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IGbChannelPlayService;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IGbChannelService;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IPTZService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcController;
|
||||
import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcMapping;
|
||||
import com.genersoft.iot.vmp.service.redisMsg.dto.RpcController;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.message.Response;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@RedisRpcController("device")
|
||||
public class RedisRpcGbDeviceController extends RpcController {
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
|
||||
|
||||
private void sendResponse(RedisRpcResponse response){
|
||||
log.info("[redis-rpc] >> {}", response);
|
||||
response.setToId(userSetting.getServerId());
|
||||
RedisRpcMessage message = new RedisRpcMessage();
|
||||
message.setResponse(response);
|
||||
redisTemplate.convertAndSend(RedisRpcConfig.REDIS_REQUEST_CHANNEL_KEY, message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 目录订阅
|
||||
*/
|
||||
@RedisRpcMapping("subscribeCatalog")
|
||||
public RedisRpcResponse subscribeCatalog(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
int id = paramJson.getIntValue("id");
|
||||
int cycle = paramJson.getIntValue("cycle");
|
||||
|
||||
RedisRpcResponse response = request.getResponse();
|
||||
|
||||
if (id <= 0) {
|
||||
response.setStatusCode(ErrorCode.ERROR400.getCode());
|
||||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
deviceService.subscribeCatalog(id, cycle);
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动位置订阅
|
||||
*/
|
||||
@RedisRpcMapping("subscribeMobilePosition")
|
||||
public RedisRpcResponse subscribeMobilePosition(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
int id = paramJson.getIntValue("id");
|
||||
int cycle = paramJson.getIntValue("cycle");
|
||||
int interval = paramJson.getIntValue("interval");
|
||||
|
||||
RedisRpcResponse response = request.getResponse();
|
||||
|
||||
if (id <= 0) {
|
||||
response.setStatusCode(ErrorCode.ERROR400.getCode());
|
||||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
deviceService.subscribeMobilePosition(id, cycle, interval);
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.service.redisMsg.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.CommonCallback;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
@@ -201,4 +202,23 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
|
||||
RedisRpcRequest request = buildRequest("streamPush/unPushStreamOnlineEvent", streamInfoParam);
|
||||
redisRpcConfig.request(request, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeCatalog(int id, int cycle) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", id);
|
||||
jsonObject.put("cycle", cycle);
|
||||
RedisRpcRequest request = buildRequest("device/subscribeCatalog", jsonObject);
|
||||
redisRpcConfig.request(request, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeMobilePosition(int id, int cycle, int interval) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", id);
|
||||
jsonObject.put("cycle", cycle);
|
||||
jsonObject.put("interval", cycle);
|
||||
RedisRpcRequest request = buildRequest("device/subscribeMobilePosition", jsonObject);
|
||||
redisRpcConfig.request(request, 10);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user