This commit is contained in:
shikong 2023-09-12 17:27:04 +08:00
parent 23782c0f8c
commit 137b96bbf7
3 changed files with 21 additions and 15 deletions

View File

@ -11,6 +11,7 @@ import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
@Slf4j
@Tag(name = "设备信息")
@ -25,7 +26,7 @@ public class Gb28181Controller {
}
@GetJson("/register")
public JsonResponse<Boolean> register(){
return JsonResponse.success(registerService.register());
public DeferredResult<JsonResponse<Boolean>> register(){
return registerService.register();
}
}

View File

@ -40,8 +40,9 @@ public class SipSender {
}
ListeningPoint listeningPoint = listeningPoints[0];
String ip = listeningPoint.getIPAddress();
int port = listeningPoint.getPort();
try {
sipProvider.sendRequest(request.build(sipProvider, ip));
sipProvider.sendRequest(request.build(sipProvider, ip, port));
} catch (SipException e) {
log.error("向{} {}:{} 发送请求失败, 异常: {}", ip, listeningPoint.getPort(), listeningPoint.getTransport(), e.getMessage());
}
@ -49,6 +50,6 @@ public class SipSender {
}
public interface SendRequest {
Request build(SipProvider provider, String ip);
Request build(SipProvider provider, String ip, int port);
}
}

View File

@ -1,33 +1,37 @@
package cn.skcks.docking.gb28181.mocking.service.gb28181.register;
import cn.skcks.docking.gb28181.core.sip.listener.SipListener;
import cn.skcks.docking.gb28181.core.sip.service.SipService;
import cn.skcks.docking.gb28181.common.json.JsonResponse;
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
import cn.skcks.docking.gb28181.mocking.config.sip.SipConfig;
import cn.skcks.docking.gb28181.mocking.core.sip.request.SipRequestBuilder;
import cn.skcks.docking.gb28181.mocking.core.sip.sender.SipSender;
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
import cn.skcks.docking.gb28181.mocking.service.device.DeviceService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;
import java.util.List;
@Slf4j
@RequiredArgsConstructor
@Service
public class RegisterService {
private final SipConfig sipConfig;
private final SipListener sipListener;
private final SipService sipService;
private final DeviceService deviceService;
private final SipSender sender;
public boolean register(){
deviceService.getAllDevice().parallelStream().forEach(device -> {
sender.sendRequest((provider, ip) -> SipRequestBuilder.createRegisterRequest(device, ip, sipConfig.getPort(), 1, SipUtil.generateFromTag(), null, provider.getNewCallId()));
});
@SneakyThrows
public DeferredResult<JsonResponse<Boolean>> register(){
DeferredResult<JsonResponse<Boolean>> result = new DeferredResult<>();
List<MockingDevice> allDevice = deviceService.getAllDevice();
allDevice.parallelStream().forEach(device -> {
sender.sendRequest((provider, ip, port) -> SipRequestBuilder.createRegisterRequest(device, ip, port, 1, SipUtil.generateFromTag(), null, provider.getNewCallId()));
return true;
});
result.setResult(JsonResponse.success(true));
return result;
}
}