Skip to content

Commit

Permalink
Merge branch 'master' into springboot3
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhom1314 committed Jan 4, 2024
2 parents dffe62b + e967f80 commit ce77496
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ private CommonUtil() { }
log.error("get localhost address error.", e);
}

String[] profiles = environment.getActiveProfiles();
if (profiles.length < 1) {
profiles = environment.getDefaultProfiles();
// fix #I8SSGQ
String env = environment.getProperty("spring.profiles.active");
if (StringUtils.isBlank(env)) {
String[] profiles = environment.getActiveProfiles();
if (profiles.length < 1) {
profiles = environment.getDefaultProfiles();
}
if (profiles.length >= 1) {
env = profiles[0];
}
}
SERVICE_INSTANCE = new ServiceInstance(address, port, appName, profiles[0]);

SERVICE_INSTANCE = new ServiceInstance(address, port, appName, env);
}

public static ServiceInstance getInstance() {
Expand All @@ -89,4 +95,4 @@ private static InetAddress getLocalHostExactAddress() throws SocketException, Un
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-example-adapter-apache-dubbo</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dynamic-tp-example-adapter-apache-dubbo-3.2.10</artifactId>

<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>3.2.10</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>3.2.10</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.dynamictp.example;

import org.dromara.dynamictp.core.spring.EnableDynamicTp;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author fabian4
*/
@EnableDubbo
@EnableDynamicTp
@SpringBootApplication
public class DubboExampleApplication {
public static void main(String[] args) {
SpringApplication.run(DubboExampleApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.dynamictp.example.controller;

import org.dromara.dynamictp.example.dubbo.DubboUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
* @author fabian4
*/
@Slf4j
@RestController
@SuppressWarnings("all")
public class TestController {

@Resource
private DubboUserService dubboUserService;

@GetMapping("/dtp-example-adapter/testDubbo")
public String testDubbo() throws InterruptedException {
return dubboUserService.getUserName(1001);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.dynamictp.example.dubbo;

/**
* DubboUserService related
*
* @author kyao
* @since 1.1.6
**/
public interface DubboUserService {

String getUserName(long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.dynamictp.example.dubbo;

import org.apache.dubbo.config.annotation.DubboService;

/**
* DubboUserServiceImpl related
*
* @author kyao
* @since 1.1.6
**/
@DubboService
public class DubboUserServiceImpl implements DubboUserService {

@Override
public String getUserName(long id) {
return "kyao";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
server:
port: 9102

spring:
application:
name: dynamic-tp-adapter-dubbo-demo

dynamic:
tp:
enabled: true
enabledCollect: true # 是否开启监控指标采集,默认false
collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer
monitorInterval: 5
platforms: # 通知报警平台配置
- platform: ding
urlKey: f80dad441fcd655438f4a08dcd6a # 替换
secret: SECb5441fa6f375d5b9d21 # 替换,非sign模式可以没有此值
receivers: 15810119805 # 钉钉账号手机号
- platform: lark
urlKey: 0d944ae7-b24a-40 # 替换
receivers: test1,test2 # 接受人飞书名称/openid
dubboTp: # dubbo 线程池配置
- threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口
threadPoolAliasName: 测试线程池
corePoolSize: 100
maximumPoolSize: 200
keepAliveTime: 60
notifyItems: # 报警项,不配置自动会按默认值配置(变更通知、容量报警、活性报警)
- type: capacity # 报警项类型,查看源码 NotifyTypeEnum枚举类
enabled: true
threshold: 80 # 报警阈值
platforms: [ ding ] # 可选配置,不配置默认拿上层platforms配置的所以平台
interval: 120 # 报警间隔(单位:s)

dubbo:
application:
name: dynamic-tp-adapter-demo
registry:
address: nacos://127.0.0.1:8848
protocol:
name: dubbo
port: 20880


# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口
# 开启 prometheus 指标采集端点
management:
metrics:
export:
prometheus:
enabled: true
endpoints:
web:
exposure:
include: '*' # 测试使用,线上不要用*,按需开启
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<module>example-adapter-apache-dubbo-2.7.3</module>
<module>example-adapter-apache-dubbo-2.7.9</module>
<module>example-adapter-apache-dubbo-3.0.7</module>
<module>example-adapter-apache-dubbo-3.2.10</module>
</modules>
</project>

0 comments on commit ce77496

Please sign in to comment.