diff --git a/gb28181-mocking-api/src/main/java/cn/skcks/docking/gb28181/mocking/api/gb28181/Gb28181Controller.java b/gb28181-mocking-api/src/main/java/cn/skcks/docking/gb28181/mocking/api/gb28181/Gb28181Controller.java index bd0d758..3a0ffb2 100644 --- a/gb28181-mocking-api/src/main/java/cn/skcks/docking/gb28181/mocking/api/gb28181/Gb28181Controller.java +++ b/gb28181-mocking-api/src/main/java/cn/skcks/docking/gb28181/mocking/api/gb28181/Gb28181Controller.java @@ -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 register(){ - return JsonResponse.success(registerService.register()); + public DeferredResult> register(){ + return registerService.register(); } } diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/sender/SipSender.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/sender/SipSender.java index f7e1b30..bc7bfb7 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/sender/SipSender.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/sender/SipSender.java @@ -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); } } diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/gb28181/register/RegisterService.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/gb28181/register/RegisterService.java index eef4927..e3350a8 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/gb28181/register/RegisterService.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/gb28181/register/RegisterService.java @@ -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> register(){ + DeferredResult> result = new DeferredResult<>(); + List 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; } }