Skip to content

Add Spring Cloud Http3 Demo #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jd.live</groupId>
<artifactId>joylive-demo-springcloud2024</artifactId>
<version>${revision}</version>
</parent>

<artifactId>joylive-demo-springcloud2024-consumer-http3</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.jd.live</groupId>
<artifactId>joylive-demo-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<build>
<directory>${basedir}/target</directory>
<finalName>joylive-demo-springcloud2024-consumer-http3</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.jd.live.agent.demo.springcloud.v2024.consumer.SpringCloud2024ConsumerHttp3</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading