Skip to content
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

feat:support agent2022 #193

Merged
merged 2 commits into from
Jun 13, 2024
Merged
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
2 changes: 1 addition & 1 deletion polaris-agent-build/conf/polaris-agent.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
plugins.enable=spring-cloud-2023-plugin
plugins.enable=spring-cloud-2022-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<module>spring-cloud-2020-examples</module>
<module>spring-cloud-hoxton-examples</module>
<module>spring-cloud-2023-examples</module>
<module>spring-cloud-2022-examples</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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">
<parent>
<artifactId>spring-cloud-plugins-examples</artifactId>
<groupId>com.tencent.polaris</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-cloud-2022-examples</artifactId>

<packaging>pom</packaging>

<modules>
<module>quickstart-examples</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM alpine:3.19.1

ARG file_name
ARG java_version

COPY ./target/${file_name} /app/main.jar

WORKDIR /app

RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories

RUN set -eux && \
apk add openjdk${java_version} && \
apk add bind-tools && \
apk add busybox-extras && \
apk add findutils && \
apk add tcpdump && \
apk add tzdata && \
apk add curl && \
apk add bash && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
date

RUN chmod 777 /app/

RUN ls -la /app/

ENTRYPOINT ["java", "-jar", "/app/main.jar"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: service-consumer-2022
name: service-consumer-2022
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: service-consumer-2022
template:
metadata:
labels:
app: service-consumer-2022
annotations:
polarismesh.cn/javaagent: "true"
polarismesh.cn/javaagentVersion: "1.7.0-RC4"
polarismesh.cn/javaagentFrameworkName: "spring-cloud"
polarismesh.cn/javaagentFrameworkVersion: "2022"
spec:
containers:
- image: polarismesh/polaris-javaagent-demo-sc-quickstart-2022-consumer:1.7.0-RC4-java17
imagePullPolicy: Always
name: consumer
resources:
limits:
cpu: "500m"
memory: 1000Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
command:
- /bin/bash
- -c
- cd /app && java -Dserver.port=65002 -jar main.jar
lifecycle:
preStop:
exec:
command: ["curl","-X","PUT","http://127.0.0.1:28080/offline","&&","sleep","30"]
readinessProbe:
httpGet:
path: /online
port: 28080
initialDelaySeconds: 3
periodSeconds: 3
restartPolicy: Always
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.8</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-javaagent-demo-sc-quickstart-2022-consumer</artifactId>
<packaging>jar</packaging>
<version>1.7.0</version>

<name>2022-consumer</name>
<description>Demo Consumer Project For Spring Cloud Alibaba</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2022.0.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2022.0.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- 简单的 Spring Cloud Web 依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<!-- 引入 Spring Cloud Alibaba 的服务注册发现依赖 -->
<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-loadbalancer</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>




</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 cn.polarismesh.agent.examples.alibaba.cloud.cloud;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
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.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;



/**
* @author <a href="mailto:[email protected]">liaochuntao</a>
*/
@SpringBootApplication
public class ConsumerApplication {

public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}

@LoadBalanced
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}


@RestController
public static class EchoController {

private RestTemplate template;

public EchoController(RestTemplate restTemplate) {
this.template = restTemplate;
}

@Autowired
@Qualifier("defaultRestTemplate")
private RestTemplate defaultRestTemplate;


@Autowired
private CircuitBreakerFactory circuitBreakerFactory;

@GetMapping("/rest")
public String circuitBreakRestTemplate() {
return circuitBreakerFactory
.create("service-provider-2022#/circuitBreak")
.run(() -> defaultRestTemplate.getForObject("/circuitBreak", String.class),
throwable -> "trigger the refuse for service callee."
);
}



@Bean
@LoadBalanced
public RestTemplate defaultRestTemplate() {
DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory("http://service-provider-2022");
RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(uriBuilderFactory);
return restTemplate;
}



@GetMapping("/echo/{str}")
public ResponseEntity<String> rest(@PathVariable String str) {
ResponseEntity<String> response = template.getForEntity("http://service-provider-2022/echo/" + str,
String.class);
return response;
}




}
@FeignClient(name = "service-provider-2022", contextId = "fallback-from-polaris")
public interface CircuitBreakerQuickstartCalleeService {

/**
* Check circuit break.
*
* @return circuit break info
*/
@GetMapping("/circuitBreak")
String circuitBreak();
}
@Component
public class CircuitBreakerQuickstartCalleeServiceFallback implements CircuitBreakerQuickstartCalleeServiceWithFallback {

@Override
public String circuitBreak() {
return "fallback: trigger the refuse for service callee.";
}
}

@FeignClient(name = "service-provider-2022", contextId = "fallback-from-code", fallback = CircuitBreakerQuickstartCalleeServiceFallback.class)
public interface CircuitBreakerQuickstartCalleeServiceWithFallback {

/**
* Check circuit break.
*
* @return circuit break info
*/
@GetMapping("/circuitBreak")
String circuitBreak();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#server.port=65002
#spring.application.name=service-consumer-2022
#spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
#spring.cloud.nacos.discovery.enabled=false
#spring.cloud.nacos.config.enabled=false
#spring.main.allow-bean-definition-overriding=true
#spring.main.allow-circular-references=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
server.port=65002
spring.application.name=service-consumer-2022
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.cloud.nacos.discovery.enabled=false
spring.cloud.nacos.config.enabled=false
spring.main.allow-bean-definition-overriding=true
spring.main.allow-circular-references=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
consumer:
serviceRouter:
plugin:
# 设置就近路由插件配置
nearbyBasedRouter:
# 描述:就近路由的最小匹配级别,需要显示设置
# 范围: zone(腾讯云地域信息,eg: ap-guangzhou)、campus(腾讯云可用区, eg: ap-guangzhou-3)
matchLevel: campus
Loading