diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/Dockerfile b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/Dockerfile new file mode 100644 index 0000000..6c45237 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/Dockerfile @@ -0,0 +1,11 @@ +FROM ghcr.io/meshware/ubuntu-oracle-jdk:17.0.9 +USER root + +ENV TZ Asia/Shanghai + +WORKDIR /export/servers/ +COPY ./target/joylive-demo-springcloud2024-consumer-http3.jar /export/servers/ + +VOLUME ["/export/servers/logs", "/export/servers/config"] +EXPOSE 18080 +ENTRYPOINT ["/bin/bash", "-c", "java ${JAVA_OPTS} ${SGM_OPTS} -jar /export/servers/joylive-demo-springcloud2024-consumer-http3.jar"] \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/deployment.yaml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/deployment.yaml new file mode 100644 index 0000000..994dc3e --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/deployment.yaml @@ -0,0 +1,183 @@ +# +# Copyright © ${year} ${owner} (${email}) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: joylive-demo-springcloud2024-consumer-http3 + x-live-enabled: "true" + name: joylive-demo-springcloud2024-consumer-http3 +spec: + replicas: 1 + selector: + matchLabels: + app: joylive-demo-springcloud2024-consumer-http3 + template: + metadata: + labels: + app: joylive-demo-springcloud2024-consumer-http3 + x-live-enabled: "true" + spec: + containers: + - env: + - name: CONFIG_LIVE_SPACE_API_TYPE + value: multilive + - name: CONFIG_LIVE_SPACE_API_URL + value: http://api.live.local/v1 + - name: CONFIG_LIVE_SPACE_API_HEADERS + value: pin=demo + - name: CONFIG_SERVICE_API_TYPE + value: jmsf + - name: CONFIG_SERVICE_API_URL + value: http://api.jmsf.local/v1 + - name: LIVE_LOG_LEVEL + value: info + - name: CONFIG_LANE_ENABLED + value: "false" + - name: NACOS_ADDR + value: nacos-server.nacos.svc:8848 + - name: NACOS_USERNAME + value: nacos + - name: NACOS_PASSWORD + value: nacos + - name: APPLICATION_NAME + value: springcloud2024-consumer-http3 + - name: APPLICATION_SERVICE_NAME + value: service-consumer-http3 + - name: APPLICATION_SERVICE_NAMESPACE + value: default + - name: SERVER_PORT + value: "18080" + - name: APPLICATION_LOCATION_REGION + value: region1 + - name: APPLICATION_LOCATION_ZONE + value: zone1 + - name: APPLICATION_LOCATION_LIVESPACE_ID + value: v4bEh4kd6Jvu5QBX09qYq-qlbcs + - name: APPLICATION_LOCATION_UNIT + value: unit1 + - name: APPLICATION_LOCATION_CELL + value: cell1 + - name: APPLICATION_LOCATION_LANESPACE_ID + value: "1" + - name: APPLICATION_LOCATION_LANE + value: production + image: hub-vpc.jdcloud.com/jmsf/joylive-demo-springcloud2024-consumer-http3:1.1.0-5aab82b3-AMD64 + imagePullPolicy: Always + name: joylive-demo-springcloud2024-consumer-http3 + ports: + - containerPort: 18080 + name: http + protocol: TCP + resources: + requests: + cpu: "4" + memory: "8Gi" + limits: + cpu: "4" + memory: "8Gi" + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: { } + terminationGracePeriodSeconds: 30 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: joylive-demo-springcloud2024-consumer-http3-gray + x-live-enabled: "true" + name: joylive-demo-springcloud2024-consumer-http3-gray +spec: + replicas: 1 + selector: + matchLabels: + app: joylive-demo-springcloud2024-consumer-http3-gray + template: + metadata: + labels: + app: joylive-demo-springcloud2024-consumer-http3-gray + x-live-enabled: "true" + spec: + containers: + - env: + - name: CONFIG_LIVE_SPACE_API_TYPE + value: multilive + - name: CONFIG_LIVE_SPACE_API_URL + value: http://api.live.local/v1 + - name: CONFIG_LIVE_SPACE_API_HEADERS + value: pin=demo + - name: CONFIG_SERVICE_API_TYPE + value: jmsf + - name: CONFIG_SERVICE_API_URL + value: http://api.jmsf.local/v1 + - name: LIVE_LOG_LEVEL + value: info + - name: CONFIG_LANE_ENABLED + value: "false" + - name: NACOS_ADDR + value: nacos-server.nacos.svc:8848 + - name: NACOS_USERNAME + value: nacos + - name: NACOS_PASSWORD + value: nacos + - name: APPLICATION_NAME + value: springcloud2024-consumer-http3-gray + - name: APPLICATION_SERVICE_NAME + value: service-consumer-http3 + - name: APPLICATION_SERVICE_NAMESPACE + value: default + - name: SERVER_PORT + value: "18080" + - name: APPLICATION_LOCATION_REGION + value: region2 + - name: APPLICATION_LOCATION_ZONE + value: zone2 + - name: APPLICATION_LOCATION_LIVESPACE_ID + value: v4bEh4kd6Jvu5QBX09qYq-qlbcs + - name: APPLICATION_LOCATION_UNIT + value: unit2 + - name: APPLICATION_LOCATION_CELL + value: cell4 + - name: APPLICATION_LOCATION_LANESPACE_ID + value: "1" + - name: APPLICATION_LOCATION_LANE + value: beta + image: hub-vpc.jdcloud.com/jmsf/joylive-demo-springcloud2024-consumer-http3:1.1.0-5aab82b3-AMD64 + imagePullPolicy: Always + name: joylive-demo-springcloud2024-consumer-http3-gray + ports: + - containerPort: 18080 + name: http + protocol: TCP + resources: + requests: + cpu: "4" + memory: "8Gi" + limits: + cpu: "4" + memory: "8Gi" + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: { } + terminationGracePeriodSeconds: 30 diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/pom.xml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/pom.xml new file mode 100644 index 0000000..da064a5 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/pom.xml @@ -0,0 +1,79 @@ + + + 4.0.0 + + com.jd.live + joylive-demo-springcloud2024 + ${revision} + + + joylive-demo-springcloud2024-consumer-http3 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + org.springframework.boot + spring-boot-starter-cache + + + com.github.ben-manes.caffeine + caffeine + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + com.jd.live + joylive-demo-api + ${revision} + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + org.projectlombok + lombok + + + + + ${basedir}/target + joylive-demo-springcloud2024-consumer-http3 + + + org.springframework.boot + spring-boot-maven-plugin + + com.jd.live.agent.demo.springcloud.v2024.consumer.SpringCloud2024ConsumerHttp3 + + + + + \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/SpringCloud2024ConsumerHttp3.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/SpringCloud2024ConsumerHttp3.java new file mode 100644 index 0000000..a34a0f2 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/SpringCloud2024ConsumerHttp3.java @@ -0,0 +1,34 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.consumer; + +import com.alibaba.nacos.client.config.utils.SnapShotSwitch; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class SpringCloud2024ConsumerHttp3 { + + public static void main(String[] args) { + SnapShotSwitch.setIsSnapShot(false); + SpringApplication.run(SpringCloud2024ConsumerHttp3.class, args); + } + +} \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/aspect/GlobalExceptionHandler.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/aspect/GlobalExceptionHandler.java new file mode 100644 index 0000000..20ae599 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/aspect/GlobalExceptionHandler.java @@ -0,0 +1,77 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.consumer.aspect; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jd.live.agent.demo.response.LiveLocation; +import com.jd.live.agent.demo.response.LiveResponse; +import com.jd.live.agent.demo.response.LiveTrace; +import com.jd.live.agent.demo.response.LiveTransmission; +import feign.FeignException; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.client.RestClientResponseException; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + @Value("${spring.application.name}") + private String applicationName; + + @Autowired + private ObjectMapper objectMapper; + + @ExceptionHandler(Exception.class) + @ResponseStatus(HttpStatus.OK) + public LiveResponse handleException(Exception e, HttpServletRequest request) { + LiveResponse response = getResponse(e); + if (response == null) { + response = new LiveResponse(500, "Internal Server Error: " + e.getMessage()); + } + response.addFirst(new LiveTrace(applicationName, LiveLocation.build(), + LiveTransmission.build("header", request::getHeader))); + return response; + } + + private LiveResponse getResponse(Exception e) { + LiveResponse response = null; + byte[] body = null; + if (e instanceof RestClientResponseException) { + RestClientResponseException exception = (RestClientResponseException) e; + body = exception.getResponseBodyAsByteArray(); + } else if (e instanceof FeignException) { + FeignException exception = (FeignException) e; + body = exception.content(); + } else if (e instanceof WebClientResponseException) { + WebClientResponseException responseException = (WebClientResponseException) e; + body = responseException.getResponseBodyAsByteArray(); + } + if (body != null) { + try { + response = objectMapper.readValue(body, LiveResponse.class); + } catch (Throwable ignore) { + } + } + return response; + } + +} \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/config/ConsumerConfig.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/config/ConsumerConfig.java new file mode 100644 index 0000000..e6484b1 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/config/ConsumerConfig.java @@ -0,0 +1,57 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.consumer.config; + +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.netty.http.HttpProtocol; +import reactor.netty.http.client.HttpClient; + +import java.time.Duration; + +@Configuration +public class ConsumerConfig { + + @LoadBalanced + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + @Bean + WebClient http3WebClient(WebClient.Builder builder) { + HttpClient client = + HttpClient.create() + // Configure HTTP/3 protocol + .protocol(HttpProtocol.HTTP3) + // Configure HTTP/3 settings + .http3Settings(spec -> spec.idleTimeout(Duration.ofSeconds(5)) + .maxData(10_000_000) + .maxStreamDataBidirectionalLocal(1_000_000)); + + return builder.clientConnector(new ReactorClientHttpConnector(client)).build(); + } + + @Bean + @LoadBalanced + public WebClient.Builder loadBalancedWebClientBuilder() { + return WebClient.builder(); + } +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/controller/EchoController.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/controller/EchoController.java new file mode 100644 index 0000000..d93d06c --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/controller/EchoController.java @@ -0,0 +1,155 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.consumer.controller; + +import com.jd.live.agent.demo.response.LiveLocation; +import com.jd.live.agent.demo.response.LiveResponse; +import com.jd.live.agent.demo.response.LiveTrace; +import com.jd.live.agent.demo.response.LiveTransmission; +import com.jd.live.agent.demo.springcloud.v2024.consumer.service.FeignService; +import com.jd.live.agent.demo.springcloud.v2024.consumer.service.NoDiscoveryRestService; +import com.jd.live.agent.demo.springcloud.v2024.consumer.service.ReactiveService; +import com.jd.live.agent.demo.springcloud.v2024.consumer.service.RestService; +import com.jd.live.agent.demo.util.CpuBusyUtil; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class EchoController { + + @Value("${spring.application.name}") + private String applicationName; + + @Value("${mock.cpuPercent:0.2}") + private double cpuPercent; + + @Resource + private RestService restService; + + @Resource + private FeignService feignService; + + @Resource + private ReactiveService reactiveService; + + @Resource + private NoDiscoveryRestService noDiscoveryRestService; + + @GetMapping({"/echo-rest/{str}", "/echo/{str}"}) + public LiveResponse echoRest(@PathVariable String str, HttpServletRequest request) { + LiveResponse response = restService.echo(str); + addTrace(request, response); + return response; + } + + @GetMapping({"/echo-origin/{str}"}) + public LiveResponse echoRestOrigin(@PathVariable String str, HttpServletRequest request) { + LiveResponse response = noDiscoveryRestService.echo(str); + addTrace(request, response); + return response; + } + + @GetMapping("/echo-feign/{str}") + public LiveResponse echoFeign(@PathVariable String str, HttpServletRequest request) { + LiveResponse response = feignService.echo(str); + addTrace(request, response); + return response; + } + + @GetMapping({"/echo-reactive/{str}"}) + public LiveResponse echoReactive(@PathVariable String str, HttpServletRequest request) { + LiveResponse response = reactiveService.echo(str); + addTrace(request, response); + return response; + } + + @GetMapping("/status-feign/{code}") + public LiveResponse statusFeign(@PathVariable int code, HttpServletRequest request) { + LiveResponse response = feignService.status(code); + addTrace(request, response); + return response; + } + + @GetMapping({"/status-rest/{code}"}) + public LiveResponse statusRest(@PathVariable int code, HttpServletRequest request) { + LiveResponse response = restService.status(code); + addTrace(request, response); + return response; + } + + @GetMapping({"/status-origin/{code}"}) + public LiveResponse statusRestOrigin(@PathVariable int code, HttpServletRequest request) { + LiveResponse response = noDiscoveryRestService.status(code); + addTrace(request, response); + return response; + } + + @GetMapping({"/status-reactive/{code}"}) + public LiveResponse statusReactive(@PathVariable int code, HttpServletRequest request) { + LiveResponse response = reactiveService.status(code); + addTrace(request, response); + return response; + } + + @GetMapping({"/exception"}) + public LiveResponse exception(HttpServletRequest request) { + LiveResponse response = restService.exception(); + addTrace(request, response); + return response; + } + + @GetMapping("/state-feign/{code}/sleep/{time}") + public String stateFeign(@PathVariable int code, @PathVariable int time, HttpServletRequest request) { + if (time > 0) { + long cpuTime = (long) (time * cpuPercent); + CpuBusyUtil.busyCompute(cpuTime); + time = (int) (time - cpuTime); + } + return feignService.state(code, time); + } + + @GetMapping({"/state-rest/{code}/sleep/{time}", "/state/{code}/sleep/{time}"}) + public String stateRest(@PathVariable int code, @PathVariable int time, HttpServletRequest request) { + if (time > 0) { + long cpuTime = (long) (time * cpuPercent); + CpuBusyUtil.busyCompute(cpuTime); + time = (int) (time - cpuTime); + } + return restService.state(code, time); + } + + @GetMapping({"/state-origin/{code}/sleep/{time}"}) + public String stateRestOrigin(@PathVariable int code, @PathVariable int time, HttpServletRequest request) { + if (time > 0) { + long cpuTime = (long) (time * cpuPercent); + CpuBusyUtil.busyCompute(cpuTime); + time = (int) (time - cpuTime); + } + return noDiscoveryRestService.state(code, time); + } + + private void addTrace(HttpServletRequest request, LiveResponse response) { + if (response != null) { + response.addFirst(new LiveTrace(applicationName, LiveLocation.build(), + LiveTransmission.build("header", request::getHeader))); + } + } + +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/FeignService.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/FeignService.java new file mode 100644 index 0000000..372affb --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/FeignService.java @@ -0,0 +1,36 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.consumer.service; + +import com.jd.live.agent.demo.response.LiveResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient(name = "service-provider") +public interface FeignService { + + @GetMapping("/echo/{str}") + LiveResponse echo(@PathVariable("str") String str); + + @GetMapping("/status/{code}") + LiveResponse status(@PathVariable("code") int code); + + @GetMapping("/state/{code}/sleep/{time}") + String state(@PathVariable("code") int code, @PathVariable("time") int time); + + +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/NoDiscoveryRestService.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/NoDiscoveryRestService.java new file mode 100644 index 0000000..d9dd5d5 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/NoDiscoveryRestService.java @@ -0,0 +1,45 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.consumer.service; + +import com.jd.live.agent.demo.response.LiveResponse; +import com.jd.live.agent.demo.service.HelloService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class NoDiscoveryRestService implements HelloService { + + private final RestTemplate restTemplate = new RestTemplate(); + + @Value("${provider.url:http://service-provider.demo.svc}") + private String providerUrl; + + @Override + public LiveResponse echo(String str) { + return restTemplate.getForObject(providerUrl + "/echo/" + str, LiveResponse.class); + } + + @Override + public LiveResponse status(int code) { + return restTemplate.getForObject(providerUrl + "/status/" + code, LiveResponse.class); + } + + public String state(int code, int time) { + return restTemplate.getForObject(providerUrl + "/state/" + code + "/sleep/" + time, String.class); + } +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/ReactiveService.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/ReactiveService.java new file mode 100644 index 0000000..a37d3db --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/ReactiveService.java @@ -0,0 +1,55 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.consumer.service; + +import com.jd.live.agent.demo.response.LiveResponse; +import com.jd.live.agent.demo.service.HelloService; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; + +@Service +public class ReactiveService implements HelloService { + + private final WebClient webClient; + + public ReactiveService(WebClient.Builder builder) { + this.webClient = builder.baseUrl("http://service-provider-reactive").build(); + } + + @Override + public LiveResponse echo(String str) { + return webClient.get() + .uri("/echo/" + str) + .retrieve() + .bodyToMono(LiveResponse.class).block(); + } + + @Override + public LiveResponse status(int code) { + return webClient.get() + .uri("/status/" + code) + .retrieve() + .bodyToMono(LiveResponse.class).block(); + } + + public String state(int code) { + return webClient.get() + .uri("/state/" + code) + .retrieve() + .bodyToMono(String.class).block(); + } + +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/RestService.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/RestService.java new file mode 100644 index 0000000..c22b9df --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/consumer/service/RestService.java @@ -0,0 +1,47 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.consumer.service; + +import com.jd.live.agent.demo.response.LiveResponse; +import com.jd.live.agent.demo.service.HelloService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class RestService implements HelloService { + + @Autowired + private RestTemplate restTemplate; + + @Override + public LiveResponse echo(String str) { + return restTemplate.getForObject("http://service-provider/echo/" + str, LiveResponse.class); + } + + @Override + public LiveResponse status(int code) { + return restTemplate.getForObject("http://service-provider/status/" + code, LiveResponse.class); + } + + public String state(int code, int time) { + return restTemplate.getForObject("http://service-provider/state/" + code + "/sleep/" + time, String.class); + } + + public LiveResponse exception() { + return restTemplate.getForObject("http://service-provider/exception", LiveResponse.class); + } +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/application.properties b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/application.properties new file mode 100644 index 0000000..f894478 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/application.properties @@ -0,0 +1,26 @@ +spring.application.name=service-consumer-http3 +server.port=${SERVER_PORT:${random.int[10000,10999]}} +server.tomcat.threads.max=${THREADS_MAX:500} +server.tomcat.threads.min-spare=${THREADS_MIN_SPARE:50} +server.tomcat.accept-count=${ACCEPT_COUNT:5000} +server.tomcat.max-connections=${MAX_CONNECTIONS:10000} +spring.cloud.nacos.discovery.server-addr=${NACOS_ADDR:${REGISTRY_INTERNAL_HOST}:${REGISTRY_INTERNAL_HTTP_PORT}} +spring.cloud.nacos.discovery.enabled=${NACOS_ENABLED:true} +spring.cloud.nacos.username=${NACOS_USERNAME:${REGISTRY_USERNAME:nacos}} +spring.cloud.nacos.password=${NACOS_PASSWORD:${REGISTRY_PASSWORD:nacos}} +spring.cloud.nacos.discovery.namespace=${NACOS_NAMESPACE:public} +spring.cloud.nacos.discovery.username=${NACOS_USERNAME:${REGISTRY_USERNAME:nacos}} +spring.cloud.nacos.discovery.password=${NACOS_PASSWORD:${REGISTRY_PASSWORD:nacos}} +#spring.cloud.nacos.discovery.ip-type=IPv6 +#spring.cloud.nacos.discovery.ip=::1 +spring.cloud.loadbalancer.cache.ttl=1s +spring.jackson.date-format=yyyy-MM-dd'T'HH:mm:ss.SSSZ +spring.jackson.default-property-inclusion=non_null +spring.jackson.serialization.indent_output=true +feign.httpclient.enabled=false +#feign.okhttp.enabled=true +#spring.main.web-application-type=none + +logging.level.root=${LIVE_LOG_LEVEL:INFO} +provider.url=${PROVIDER_URL:http://service-provider.demo.svc} +mock.cpuPercent=${CPU_PERCENT:0.2} \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/nacos-logback.xml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/nacos-logback.xml new file mode 100644 index 0000000..8fc27e1 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/nacos-logback.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/static/index.html b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/static/index.html new file mode 100644 index 0000000..ba7c290 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-consumer-http3/src/main/resources/static/index.html @@ -0,0 +1 @@ +

Hello World!

\ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/Dockerfile b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/Dockerfile new file mode 100644 index 0000000..e9fbb41 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/Dockerfile @@ -0,0 +1,11 @@ +FROM ghcr.io/meshware/ubuntu-oracle-jdk:17.0.9 +USER root + +ENV TZ Asia/Shanghai + +WORKDIR /export/servers/ +COPY ./target/joylive-demo-springcloud2024-gateway-http3.jar /export/servers/ + +VOLUME ["/export/servers/logs", "/export/servers/config"] +EXPOSE 8888 +ENTRYPOINT ["/bin/bash", "-c", "java ${JAVA_OPTS} -jar /export/servers/joylive-demo-springcloud2024-gateway-http3.jar"] \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/deployment.yaml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/deployment.yaml new file mode 100644 index 0000000..b4137be --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/deployment.yaml @@ -0,0 +1,187 @@ +# +# Copyright © ${year} ${owner} (${email}) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: joylive-demo-springcloud2024-gateway-http3 + x-live-enabled: "true" + name: joylive-demo-springcloud2024-gateway-http3 +spec: + replicas: 1 + selector: + matchLabels: + app: joylive-demo-springcloud2024-gateway-http3 + template: + metadata: + labels: + app: joylive-demo-springcloud2024-gateway-http3 + x-live-enabled: "true" + spec: + containers: + - env: + - name: CONFIG_LIVE_SPACE_API_TYPE + value: multilive + - name: CONFIG_LIVE_SPACE_API_URL + value: http://api.live.local/v1 + - name: CONFIG_LIVE_SPACE_API_HEADERS + value: pin=demo + - name: CONFIG_SERVICE_API_TYPE + value: jmsf + - name: CONFIG_SERVICE_API_URL + value: http://api.jmsf.local/v1 + - name: LIVE_LOG_LEVEL + value: info + - name: CONFIG_LANE_ENABLED + value: "false" + - name: NACOS_ADDR + value: nacos-server.nacos.svc:8848 + - name: NACOS_USERNAME + value: nacos + - name: NACOS_PASSWORD + value: nacos + - name: APPLICATION_NAME + value: springcloud2024-gateway-http3 + - name: APPLICATION_SERVICE_NAMESPACE + value: default + - name: APPLICATION_LOCATION_REGION + value: region1 + - name: APPLICATION_LOCATION_ZONE + value: zone1 + - name: APPLICATION_LOCATION_LIVESPACE_ID + value: v4bEh4kd6Jvu5QBX09qYq-qlbcs + - name: APPLICATION_LOCATION_UNIT + value: unit1 + - name: APPLICATION_LOCATION_CELL + value: cell1 + - name: APPLICATION_SERVICE_GATEWAY + value: FRONTEND + image: hub-vpc.jdcloud.com/jmsf/joylive-demo-springcloud2024-gateway-http3:1.1.0-5aab82b3-AMD64 + imagePullPolicy: Always + name: joylive-demo-springcloud2024-gateway-http3 + ports: + - containerPort: 8888 + name: http + protocol: TCP + resources: + requests: + cpu: "1" + memory: "1Gi" + limits: + cpu: "1" + memory: "1Gi" + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: { } + terminationGracePeriodSeconds: 30 + +--- +apiVersion: v1 +kind: Service +metadata: + name: springcloud2024-gateway-http3 +spec: + type: NodePort + ports: + - port: 8888 + protocol: TCP + targetPort: http + selector: + app: joylive-demo-springcloud2024-gateway-http3 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: joylive-demo-springcloud2024-gateway-http3-gray + x-live-enabled: "true" + name: joylive-demo-springcloud2024-gateway-http3-gray +spec: + replicas: 1 + selector: + matchLabels: + app: joylive-demo-springcloud2024-gateway-http3-gray + template: + metadata: + labels: + app: joylive-demo-springcloud2024-gateway-http3-gray + x-live-enabled: "true" + spec: + containers: + - env: + - name: LIVE_LOG_LEVEL + value: info + - name: CONFIG_LANE_ENABLED + value: "false" + - name: NACOS_ADDR + value: nacos-server.nacos.svc:8848 + - name: NACOS_USERNAME + value: nacos + - name: NACOS_PASSWORD + value: nacos + - name: APPLICATION_NAME + value: springcloud2024-gateway-http3-gray + - name: APPLICATION_SERVICE_NAMESPACE + value: default + - name: APPLICATION_LOCATION_REGION + value: region2 + - name: APPLICATION_LOCATION_LIVESPACE_ID + value: v4bEh4kd6Jvu5QBX09qYq-qlbcs + - name: APPLICATION_LOCATION_UNIT + value: unit2 + - name: APPLICATION_LOCATION_CELL + value: cell4 + - name: APPLICATION_SERVICE_GATEWAY + value: FRONTEND + image: hub-vpc.jdcloud.com/jmsf/joylive-demo-springcloud2024-gateway-http3:1.1.0-5aab82b3-AMD64 + imagePullPolicy: Always + name: joylive-demo-springcloud2024-gateway-http3-gray + ports: + - containerPort: 8888 + name: http + protocol: TCP + resources: + requests: + cpu: "1" + memory: "1Gi" + limits: + cpu: "1" + memory: "1Gi" + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: { } + terminationGracePeriodSeconds: 30 + +--- +apiVersion: v1 +kind: Service +metadata: + name: springcloud2024-gateway-http3-gray +spec: + type: NodePort + ports: + - port: 8888 + protocol: TCP + targetPort: http + selector: + app: joylive-demo-springcloud2024-gateway-http3-gray \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/pom.xml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/pom.xml new file mode 100644 index 0000000..523b2b5 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + com.jd.live + joylive-demo-springcloud2024 + ${revision} + + + joylive-demo-springcloud2024-gateway-http3 + + + 4.1.112.Final + 2.1.1 + + + + + com.jd.live + joylive-demo-api + ${revision} + + + + io.netty + netty-all + ${netty.version} + + + org.springframework.cloud + spring-cloud-starter-gateway + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.cloud + spring-cloud-loadbalancer + + + org.springframework.boot + spring-boot-starter-cache + + + com.github.ben-manes.caffeine + caffeine + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + org.springframework.boot + spring-boot-starter-actuator + + + + + ${basedir}/target + joylive-demo-springcloud2024-gateway-http3 + + + org.springframework.boot + spring-boot-maven-plugin + + com.jd.live.agent.demo.springcloud.v2024.gateway.SpringCloud2024GatewayHttp3 + + + + + \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/SpringCloud2024GatewayHttp3.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/SpringCloud2024GatewayHttp3.java new file mode 100644 index 0000000..5c2162d --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/SpringCloud2024GatewayHttp3.java @@ -0,0 +1,29 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.gateway; + +import com.alibaba.nacos.client.config.utils.SnapShotSwitch; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringCloud2024GatewayHttp3 { + + public static void main(String[] args) { + SnapShotSwitch.setIsSnapShot(false); + SpringApplication.run(SpringCloud2024GatewayHttp3.class, args); + } +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/config/GatewayConfiguration.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/config/GatewayConfiguration.java new file mode 100644 index 0000000..e4dcbea --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/config/GatewayConfiguration.java @@ -0,0 +1,39 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.gateway.config; + +import org.springframework.cloud.gateway.config.HttpClientCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import reactor.netty.http.HttpProtocol; + +import java.time.Duration; + +@Configuration +class GatewayConfiguration { + + @Bean + HttpClientCustomizer http3HttpClientCustomizer() { + return httpClient -> + httpClient + // Configure HTTP/3 protocol + .protocol(HttpProtocol.HTTP3) + // Configure HTTP/3 settings + .http3Settings(spec -> spec.idleTimeout(Duration.ofSeconds(5)) + .maxData(10_000_000) + .maxStreamDataBidirectionalLocal(1_000_000)); + } +} \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/config/Http3NettyWebServerCustomizer.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/config/Http3NettyWebServerCustomizer.java new file mode 100644 index 0000000..6fef67b --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/config/Http3NettyWebServerCustomizer.java @@ -0,0 +1,49 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.gateway.config; + +import org.springframework.boot.ssl.SslBundle; +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; +import reactor.netty.http.Http3SslContextSpec; +import reactor.netty.http.HttpProtocol; + +import java.time.Duration; + +@Component +class Http3NettyWebServerCustomizer implements WebServerFactoryCustomizer { + + @Override + public void customize(NettyReactiveWebServerFactory factory) { + factory.addServerCustomizers(server -> { + SslBundle sslBundle = factory.getSslBundles().getBundle("server-http3"); + Http3SslContextSpec sslContextSpec = + Http3SslContextSpec.forServer(sslBundle.getManagers().getKeyManagerFactory(), sslBundle.getKey().getPassword()); + + return server + // Configure HTTP/3 protocol + .protocol(HttpProtocol.HTTP3) + // Configure HTTP/3 SslContext + .secure(spec -> spec.sslContext(sslContextSpec)) + // Configure HTTP/3 settings + .http3Settings(spec -> spec.idleTimeout(Duration.ofSeconds(5)) + .maxData(10_000_000) + .maxStreamDataBidirectionalRemote(1_000_000) + .maxStreamsBidirectional(100)); + }); + } +} \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/filter/LiveGatewayFilter.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/filter/LiveGatewayFilter.java new file mode 100644 index 0000000..c3cede2 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/gateway/filter/LiveGatewayFilter.java @@ -0,0 +1,119 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.gateway.filter; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jd.live.agent.demo.response.LiveLocation; +import com.jd.live.agent.demo.response.LiveResponse; +import com.jd.live.agent.demo.response.LiveTrace; +import com.jd.live.agent.demo.response.LiveTransmission; +import org.reactivestreams.Publisher; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.http.server.reactive.ServerHttpResponseDecorator; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Component +public class LiveGatewayFilter implements GlobalFilter, Ordered { + + @Value("${spring.application.name}") + private String applicationName; + + private final ObjectMapper objectMapper; + + public LiveGatewayFilter(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public int getOrder() { + return -2; + } + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + ServerHttpRequest request = exchange.getRequest(); + ServerHttpResponse response = exchange.getResponse(); + ServerHttpResponse decorator = new LiveTraceDecorator(response, request); + + return chain.filter(exchange.mutate().response(decorator).build()).onErrorResume(throwable -> { + if (response.isCommitted()) { + return Mono.error(throwable); + } + LiveResponse liveResponse = new LiveResponse(LiveResponse.ERROR, throwable.getMessage()); + addTrace(liveResponse, request.getHeaders()); + try { + byte[] data = objectMapper.writeValueAsBytes(liveResponse); + response.getHeaders().setContentLength(data.length); + return response.writeWith(Mono.just(response.bufferFactory().wrap(data))); + } catch (JsonProcessingException e) { + return Mono.error(throwable); + } + }); + } + + private void addTrace(LiveResponse liveResponse, HttpHeaders headers) { + liveResponse.addFirst(new LiveTrace(applicationName, LiveLocation.build(), + LiveTransmission.build("header", headers::getFirst))); + } + + private class LiveTraceDecorator extends ServerHttpResponseDecorator { + private final ServerHttpRequest request; + + LiveTraceDecorator(ServerHttpResponse response, + ServerHttpRequest request) { + super(response); + this.request = request; + } + + @Override + public Mono writeWith(Publisher body) { + if (getDelegate().getStatusCode() == HttpStatus.OK && body instanceof Flux) { + Flux fluxBody = Flux.from(body); + ServerHttpResponse delegate = getDelegate(); + HttpHeaders headers = request.getHeaders(); + return super.writeWith(fluxBody.buffer().map(dataBuffers -> { + DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); + DataBuffer join = dataBufferFactory.join(dataBuffers); + byte[] array = join.asByteBuffer().array(); + try { + LiveResponse liveResponse = objectMapper.readValue(array, LiveResponse.class); + addTrace(liveResponse, headers); + byte[] data = objectMapper.writeValueAsBytes(liveResponse); + delegate.getHeaders().setContentLength(data.length); + return delegate.bufferFactory().wrap(data); + } catch (Throwable ignore) { + return delegate.bufferFactory().wrap(array); + } + })); + } + return super.writeWith(body); + } + } +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/application.yaml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/application.yaml new file mode 100644 index 0000000..4d7649e --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/application.yaml @@ -0,0 +1,97 @@ +server: + port: ${SERVER_PORT:8888} +management: + endpoint: + gateway: + enabled: true + endpoints: + web: + exposure: + include: "gateway" +spring: + application: + name: spring-gateway-http3 + jackson: + date-format: yyyy-MM-dd'T'HH:mm:ss.SSSZ + default-property-inclusion: non_null + serialization: + indent_output: true + cloud: + gateway: + routes: + - id: rocketmq + uri: lb://service-rocketmq + predicates: + - Path=/service-rocketmq/** + - Method=GET + filters: + - StripPrefix=1 + - id: order + uri: lb://service-order + predicates: + - Path=/service-order/** + filters: + - StripPrefix=1 + - id: consumer + uri: lb://service-consumer + predicates: + - Path=/service-consumer/** + - Method=GET + filters: + - StripPrefix=1 + - id: provider-reactive + uri: lb://service-provider-reactive + predicates: + - Path=/service-provider-reactive/** + - Method=GET + filters: + - StripPrefix=1 + - Retry=5 + - id: provider + uri: lb://service-provider + predicates: + - Path=/service-provider/** + - Method=GET + filters: + - StripPrefix=1 + - Retry=5 + - id: http + uri: http://demo.live.local:11813/ + predicates: + - Path=/http/** + - Method=GET + filters: + - StripPrefix=1 + discovery: + locator: + enabled: true + global-filter: + websocket-routing: + enabled: false + nacos: + discovery: + server-addr: ${NACOS_ADDR:${REGISTRY_INTERNAL_HOST}:${REGISTRY_INTERNAL_HTTP_PORT}} + username: ${NACOS_USERNAME:${REGISTRY_USERNAME:nacos}} + password: ${NACOS_PASSWORD:${REGISTRY_PASSWORD:nacos}} + namespace: ${NACOS_NAMESPACE:public} + ssl: + bundle: + jks: + server-http3: + key: + alias: https + keystore: + location: classpath:keystore.jks + password: 123456 + type: JKS + +logging: + level: + org: + springframework: + cloud: + gateway: ${LIVE_LOG_LEVEL:INFO} + reactor: + netty: ${LIVE_LOG_LEVEL:INFO} + root: ${LIVE_LOG_LEVEL:INFO} + diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/keystore.jks b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/keystore.jks new file mode 100644 index 0000000..a73f153 Binary files /dev/null and b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/keystore.jks differ diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/nacos-logback.xml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/nacos-logback.xml new file mode 100644 index 0000000..8fc27e1 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-gateway-http3/src/main/resources/nacos-logback.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/Dockerfile b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/Dockerfile new file mode 100644 index 0000000..18911a1 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/Dockerfile @@ -0,0 +1,11 @@ +FROM ghcr.io/meshware/ubuntu-oracle-jdk:17.0.9 +USER root + +ENV TZ Asia/Shanghai + +WORKDIR /export/servers/ +COPY ./target/joylive-demo-springcloud2024-provider-http3.jar /export/servers/ + +VOLUME ["/export/servers/logs", "/export/servers/config"] +EXPOSE 18081 +ENTRYPOINT ["/bin/bash", "-c", "java ${JAVA_OPTS} -jar /export/servers/joylive-demo-springcloud2024-provider-http3.jar"] \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/deployment.yaml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/deployment.yaml new file mode 100644 index 0000000..7ef9a3a --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/deployment.yaml @@ -0,0 +1,184 @@ +# +# Copyright © ${year} ${owner} (${email}) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: joylive-demo-springcloud2024-provider-http3 + x-live-enabled: "true" + name: joylive-demo-springcloud2024-provider-http3 +spec: + replicas: 1 + selector: + matchLabels: + app: joylive-demo-springcloud2024-provider-http3 + template: + metadata: + labels: + app: joylive-demo-springcloud2024-provider-http3 + x-live-enabled: "true" + spec: + containers: + - env: + - name: CONFIG_LIVE_SPACE_API_TYPE + value: multilive + - name: CONFIG_LIVE_SPACE_API_URL + value: http://api.live.local/v1 + - name: CONFIG_LIVE_SPACE_API_HEADERS + value: pin=demo + - name: CONFIG_SERVICE_API_TYPE + value: jmsf + - name: CONFIG_SERVICE_API_URL + value: http://api.jmsf.local/v1 + - name: LIVE_LOG_LEVEL + value: info + - name: CONFIG_LANE_ENABLED + value: "false" + - name: NACOS_ADDR + value: nacos-server.nacos.svc:8848 + - name: NACOS_USERNAME + value: nacos + - name: NACOS_PASSWORD + value: nacos + - name: APPLICATION_NAME + value: springcloud2024-provider + - name: APPLICATION_SERVICE_NAME + value: service-provider + - name: APPLICATION_SERVICE_NAMESPACE + value: default + - name: SERVER_PORT + value: "18081" + - name: APPLICATION_LOCATION_REGION + value: region1 + - name: APPLICATION_LOCATION_ZONE + value: zone1 + - name: APPLICATION_LOCATION_LIVESPACE_ID + value: v4bEh4kd6Jvu5QBX09qYq-qlbcs + - name: APPLICATION_LOCATION_UNIT + value: unit1 + - name: APPLICATION_LOCATION_CELL + value: cell1 + - name: APPLICATION_LOCATION_LANESPACE_ID + value: "1" + - name: APPLICATION_LOCATION_LANE + value: production + image: hub-vpc.jdcloud.com/jmsf/joylive-demo-springcloud2024-provider-http3:1.1.0-310d12bd-AMD64 + imagePullPolicy: Always + name: joylive-demo-springcloud2024-provider-http3 + ports: + - containerPort: 18081 + name: http + protocol: TCP + resources: + requests: + cpu: "4" + memory: "8Gi" + limits: + cpu: "4" + memory: "8Gi" + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: { } + terminationGracePeriodSeconds: 30 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: joylive-demo-springcloud2024-provider-http3-gray + x-live-enabled: "true" + name: joylive-demo-springcloud2024-provider-http3-gray +spec: + replicas: 1 + selector: + matchLabels: + app: joylive-demo-springcloud2024-provider-http3-gray + template: + metadata: + labels: + app: joylive-demo-springcloud2024-provider-http3-gray + x-live-enabled: "true" + spec: + containers: + - env: + - name: CONFIG_LIVE_SPACE_API_TYPE + value: multilive + - name: CONFIG_LIVE_SPACE_API_URL + value: http://api.live.local/v1 + - name: CONFIG_LIVE_SPACE_API_HEADERS + value: pin=demo + - name: CONFIG_SERVICE_API_TYPE + value: jmsf + - name: CONFIG_SERVICE_API_URL + value: http://api.jmsf.local/v1 + - name: LIVE_LOG_LEVEL + value: info + - name: CONFIG_LANE_ENABLED + value: "false" + - name: NACOS_ADDR + value: nacos-server.nacos.svc:8848 + - name: NACOS_USERNAME + value: nacos + - name: NACOS_PASSWORD + value: nacos + - name: APPLICATION_NAME + value: springcloud2024-provider-gray + - name: APPLICATION_SERVICE_NAME + value: service-provider + - name: APPLICATION_SERVICE_NAMESPACE + value: default + - name: SERVER_PORT + value: "18081" + - name: APPLICATION_LOCATION_REGION + value: region2 + - name: APPLICATION_LOCATION_ZONE + value: zone2 + - name: APPLICATION_LOCATION_LIVESPACE_ID + value: v4bEh4kd6Jvu5QBX09qYq-qlbcs + - name: APPLICATION_LOCATION_UNIT + value: unit2 + - name: APPLICATION_LOCATION_CELL + value: cell4 + - name: APPLICATION_LOCATION_LANESPACE_ID + value: "1" + - name: APPLICATION_LOCATION_LANE + value: beta + image: hub-vpc.jdcloud.com/jmsf/joylive-demo-springcloud2024-provider-http3:1.1.0-310d12bd-AMD64 + imagePullPolicy: Always + name: joylive-demo-springcloud2024-provider-http3-gray + ports: + - containerPort: 18081 + name: http + protocol: TCP + resources: + requests: + cpu: "4" + memory: "8Gi" + limits: + cpu: "4" + memory: "8Gi" + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: { } + terminationGracePeriodSeconds: 30 + diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/pom.xml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/pom.xml new file mode 100644 index 0000000..449a1e9 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + com.jd.live + joylive-demo-springcloud2024 + ${revision} + + + joylive-demo-springcloud2024-provider-http3 + + + + + com.jd.live + joylive-demo-api + ${revision} + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-webflux + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + org.springframework.boot + spring-boot-starter-actuator + + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + + + + ${basedir}/target + joylive-demo-springcloud2024-provider-http3 + + + org.springframework.boot + spring-boot-maven-plugin + + com.jd.live.agent.demo.springcloud.v2024.provider.SpringCloud2024ProviderHttp3 + + + + + \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/SpringCloud2024ProviderHttp3.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/SpringCloud2024ProviderHttp3.java new file mode 100644 index 0000000..7ec9d39 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/SpringCloud2024ProviderHttp3.java @@ -0,0 +1,32 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.provider; + +import com.alibaba.nacos.client.config.utils.SnapShotSwitch; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@EnableDiscoveryClient +@SpringBootApplication +public class SpringCloud2024ProviderHttp3 { + + public static void main(String[] args) { + SnapShotSwitch.setIsSnapShot(false); + SpringApplication.run(SpringCloud2024ProviderHttp3.class, args); + } + +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/aspect/GlobalExceptionHandler.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/aspect/GlobalExceptionHandler.java new file mode 100644 index 0000000..0b46262 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/aspect/GlobalExceptionHandler.java @@ -0,0 +1,49 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.provider.aspect; + +import com.jd.live.agent.demo.response.LiveLocation; +import com.jd.live.agent.demo.response.LiveResponse; +import com.jd.live.agent.demo.response.LiveTrace; +import com.jd.live.agent.demo.response.LiveTransmission; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + @Value("${spring.application.name}") + private String applicationName; + + @ExceptionHandler(Exception.class) + @ResponseStatus(HttpStatus.OK) + public Mono handleException(Exception e, ServerWebExchange exchange) { + return Mono.fromSupplier(() -> { + HttpHeaders headers = exchange.getRequest().getHeaders(); + LiveResponse response = new LiveResponse(500, "Internal Server Error: " + e.getMessage()); + response.addFirst(new LiveTrace(applicationName, LiveLocation.build(), + LiveTransmission.build("header", headers::getFirst))); + return response; + }); + } + +} \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/config/Http3NettyWebServerCustomizer.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/config/Http3NettyWebServerCustomizer.java new file mode 100644 index 0000000..df2f8b9 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/config/Http3NettyWebServerCustomizer.java @@ -0,0 +1,49 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.provider.config; + +import org.springframework.boot.ssl.SslBundle; +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; +import reactor.netty.http.Http3SslContextSpec; +import reactor.netty.http.HttpProtocol; + +import java.time.Duration; + +@Component +class Http3NettyWebServerCustomizer implements WebServerFactoryCustomizer { + + @Override + public void customize(NettyReactiveWebServerFactory factory) { + factory.addServerCustomizers(server -> { + SslBundle sslBundle = factory.getSslBundles().getBundle("server-http3"); + Http3SslContextSpec sslContextSpec = + Http3SslContextSpec.forServer(sslBundle.getManagers().getKeyManagerFactory(), sslBundle.getKey().getPassword()); + + return server + // Configure HTTP/3 protocol + .protocol(HttpProtocol.HTTP3) + // Configure HTTP/3 SslContext + .secure(spec -> spec.sslContext(sslContextSpec)) + // Configure HTTP/3 settings + .http3Settings(spec -> spec.idleTimeout(Duration.ofSeconds(5)) + .maxData(10_000_000) + .maxStreamDataBidirectionalRemote(1_000_000) + .maxStreamsBidirectional(100)); + }); + } +} \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/config/RouterConfig.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/config/RouterConfig.java new file mode 100644 index 0000000..03c89ee --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/config/RouterConfig.java @@ -0,0 +1,32 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.provider.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; + +@Configuration +public class RouterConfig { + + @Bean + public RouterFunction staticResourceRouter() { + return RouterFunctions.resources("/static/**", new ClassPathResource("static/")); + } +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/controller/EchoController.java b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/controller/EchoController.java new file mode 100644 index 0000000..958b311 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/java/com/jd/live/agent/demo/springcloud/v2024/provider/controller/EchoController.java @@ -0,0 +1,76 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jd.live.agent.demo.springcloud.v2024.provider.controller; + +import com.jd.live.agent.demo.response.LiveLocation; +import com.jd.live.agent.demo.response.LiveResponse; +import com.jd.live.agent.demo.response.LiveTrace; +import com.jd.live.agent.demo.response.LiveTransmission; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.util.concurrent.CountDownLatch; + +@RestController +public class EchoController { + + @Value("${spring.application.name}") + private String applicationName; + + private final CountDownLatch latch = new CountDownLatch(1); + + @GetMapping("/echo/{str}") + public Mono echo(@PathVariable String str, ServerWebExchange exchange) { + return Mono.fromSupplier(() -> { + LiveResponse response = new LiveResponse(str); + configure(exchange, response); + return response; + }); + } + + @GetMapping("/status/{code}") + public Mono status(@PathVariable int code, ServerWebExchange exchange) { + return Mono.defer(() -> { + HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; + try { + status = HttpStatus.valueOf(code); + } catch (Exception ignored) { + } + exchange.getResponse().setStatusCode(status); + LiveResponse response = new LiveResponse(code, null, code); + configure(exchange, response); + return Mono.just(response); + }); + } + + @GetMapping("/exception") + public Mono exception(ServerWebExchange exchange) { + return Mono.error(new RuntimeException("exception")); + } + + private void configure(ServerWebExchange exchange, LiveResponse response) { + HttpHeaders headers = exchange.getRequest().getHeaders(); + response.addFirst(new LiveTrace(applicationName, LiveLocation.build(), + LiveTransmission.build("header", headers::getFirst))); + } + +} diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/application.properties b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/application.properties new file mode 100755 index 0000000..a6249ec --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/application.properties @@ -0,0 +1,25 @@ +server.port=${SERVER_PORT:${random.int[11000,11999]}} +spring.application.name=service-provider-http3 +spring.cloud.nacos.discovery.server-addr=${NACOS_ADDR:${REGISTRY_INTERNAL_HOST}:${REGISTRY_INTERNAL_HTTP_PORT}} +spring.cloud.nacos.discovery.enabled=${NACOS_ENABLED:true} +#spring.cloud.nacos.discovery.instance-enabled=true +#register IPv6 +#spring.cloud.nacos.discovery.ip-type=IPv6 +#spring.cloud.nacos.discovery.ip=::1 +spring.cloud.nacos.username=${NACOS_USERNAME:${REGISTRY_USERNAME:nacos}} +spring.cloud.nacos.password=${NACOS_PASSWORD:${REGISTRY_PASSWORD:nacos}} +spring.cloud.nacos.discovery.namespace=${NACOS_NAMESPACE:public} +spring.cloud.nacos.discovery.username=${NACOS_USERNAME:${REGISTRY_USERNAME:nacos}} +spring.cloud.nacos.discovery.password=${NACOS_PASSWORD:${REGISTRY_PASSWORD:nacos}} +spring.jackson.serialization.indent_output=true +spring.jackson.date-format=yyyy-MM-dd'T'HH:mm:ss.SSSZ +spring.jackson.default-property-inclusion=non_null +logging.level.root=${LIVE_LOG_LEVEL:INFO} +management.endpoints.web.exposure.include=* +management.endpoint.health.show-details=always + +#HTTP3 settings +spring.ssl.bundle.jks.server-http3.key.alias=https +spring.ssl.bundle.jks.server-http3.keystore.location=classpath:keystore.jks +spring.ssl.bundle.jks.server-http3.keystore.password=123456 +spring.ssl.bundle.jks.server-http3.keystore.type=JKS \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/keystore.jks b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/keystore.jks new file mode 100644 index 0000000..a73f153 Binary files /dev/null and b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/keystore.jks differ diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/nacos-logback.xml b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/nacos-logback.xml new file mode 100644 index 0000000..8fc27e1 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/nacos-logback.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/static/live.js b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/static/live.js new file mode 100644 index 0000000..92f6ac0 --- /dev/null +++ b/joylive-demo-springcloud2024/joylive-demo-springcloud2024-provider-http3/src/main/resources/static/live.js @@ -0,0 +1 @@ +var Live \ No newline at end of file diff --git a/joylive-demo-springcloud2024/pom.xml b/joylive-demo-springcloud2024/pom.xml index 9dbdaa0..d8151f5 100644 --- a/joylive-demo-springcloud2024/pom.xml +++ b/joylive-demo-springcloud2024/pom.xml @@ -23,9 +23,12 @@ joylive-demo-springcloud2024-provider joylive-demo-springcloud2024-provider-reactive + joylive-demo-springcloud2024-provider-http3 joylive-demo-springcloud2024-consumer + joylive-demo-springcloud2024-consumer-http3 joylive-demo-springcloud2024-gateway joylive-demo-springcloud2024-gateway-tomcat + joylive-demo-springcloud2024-gateway-http3