Skip to content

Commit

Permalink
tag 2021.01.30 test otel enhance to sofa rpc for myself. committer:陈晨。
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmudu committed Jan 29, 2021
1 parent 243da51 commit 6ee9b91
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public class TaskExecutorConfig {
*
* @return
*/
// @Bean(name = "taskExecutor") find type == TaskExector and name.equals("taskExector")
// @Primary
// @Bean(name = "taskExecutor") find type == TaskExector and name.equals("taskExector")
// @Primary
@Bean(name = "cchenThreadExector")
public ThreadPoolTaskExecutor taskExecutor(){
public ThreadPoolTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(20);
Expand All @@ -57,38 +57,35 @@ public ThreadPoolTaskExecutor taskExecutor(){
taskExecutor.initialize();
return taskExecutor;
}

class customizableThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
@Override
public void execute(Runnable task) {
super.execute(task);
}

}

/**
* copy form DefaultThreadFactory.
* [88d49c5a4575e7763bed898862e01d22,dfd1279e70b0ef7a]- o.c.o.a.s.i.OtelTestAsyncServiceImpl.calledAsync:34
* OtelTestAsyncServiceImpl calledAsync thread is : cchen-pool-1-thread-1
*/
class CustomizableThreadFactory implements ThreadFactory {

private final AtomicInteger poolNumber = new AtomicInteger(1);
private final ThreadGroup group;
private final AtomicInteger poolNumber = new AtomicInteger(1);
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
private final String namePrefix;

CustomizableThreadFactory() {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
namePrefix = "cchen-pool-" +
poolNumber.getAndIncrement() +
"-thread-";
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
namePrefix = "cchen-pool-" + poolNumber.getAndIncrement() + "-thread-";
}

public Thread newThread(Runnable r) {
Thread t = new Thread(group, r,
namePrefix + threadNumber.getAndIncrement(),
0);
Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0);
if (t.isDaemon())
t.setDaemon(false);
if (t.getPriority() != Thread.NORM_PRIORITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public class OtelTestRestClientController {
@GetMapping("/rest")
public String rest() throws Exception {
log.info("OtelTestRestClientController started!");
// httpClient();
// asyncHttpClient();
// httpClient();
// asyncHttpClient();
restTemplate();
asyncRestTemplate();
// connectionUrl();
// syncOkHttp();
// asyncOkHttp();
// connectionUrl();
// syncOkHttp();
// asyncOkHttp();
return "OtelTestRestClientController hello !";
}

Expand Down
11 changes: 11 additions & 0 deletions otel-simple-sofarpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Open-Telemetry-Simple-SofaRpc 案例工程

> Open-Telemetry-Simple-SofaRpc 实际测试了个人为在Otel中为Sofa-Rpc所作的增强(个人测试使用)。
##### 测试模块快速开始

1. 确保[Guides 案例工程下的步骤](../README.md)执行完毕。

2. 启动此模块[otel-simple-sofarpc](https://github.com/chenmudu/open-telemetry-java-guides/tree/master/otel-simple-sofarpc/src/main/java/org/chenmudu/otel/sofarpc/quickly)下的QuickStartServer 和 QuickStartClient.

3. 测试个人为sofa-rpc 在Otel中增强其RPC的功能。
26 changes: 26 additions & 0 deletions otel-simple-sofarpc/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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>open-telemetry-java-guides</artifactId>
<groupId>org.chenmudu.otel</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>otel-simple-sofarpc</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-all</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.chenmudu.otel.sofarpc.quickly;

/**
* Quick Start demo interface
*/
public interface HelloService {
String sayHello(String string);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.chenmudu.otel.sofarpc.quickly;

/**
* Quick Start demo implements
*/
public class HelloServiceImpl implements HelloService {

//private final static Logger LOGGER = LoggerFactory.getLogger(HelloServiceImpl.class);

@Override
public String sayHello(String string) {
System.out.println("Server receive: " + string);
return "hello " + string + " !";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.chenmudu.otel.sofarpc.quickly;

import com.alipay.sofa.rpc.config.ConsumerConfig;

/**
* Quick Start client
*/
public class QuickStartClient {

// private final static Logger LOGGER = LoggerFactory.getLogger(QuickStartClient.class);

public static void main(String[] args) {

ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>()
.setInterfaceId(HelloService.class.getName()) // 指定接口
.setProtocol("bolt") // 指定协议
.setDirectUrl("bolt://127.0.0.1:12200") // 指定直连地址
.setConnectTimeout(10 * 1000);

HelloService helloService = consumerConfig.refer();

while (true) {
try {
System.out.println(helloService.sayHello("world"));
} catch (Exception e) {
e.printStackTrace();
}

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.chenmudu.otel.sofarpc.quickly;

import com.alipay.sofa.rpc.config.ProviderConfig;
import com.alipay.sofa.rpc.config.ServerConfig;

/**
* Quick Start Server
*/
public class QuickStartServer {

public static void main(String[] args) {
ServerConfig serverConfig = new ServerConfig().setProtocol("bolt") // 设置一个协议,默认bolt
.setPort(12200) // 设置一个端口,默认12200
.setDaemon(false); // 非守护线程

ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
.setInterfaceId(HelloService.class.getName()) // 指定接口
.setRef(new HelloServiceImpl()) // 指定实现
.setServer(serverConfig); // 指定服务端

providerConfig.export(); // 发布服务
}
}
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<otel.version>0.12.0</otel.version>
<otel-exporter.version>0.9.1</otel-exporter.version>
<project.encoding>UTF-8</project.encoding>
<sofa.rpc.version>5.5.9</sofa.rpc.version>
<springboot.version>2.1.14.RELEASE</springboot.version>
</properties>

Expand All @@ -41,6 +42,7 @@
<module>otel-simple-webflux</module>
<module>otel-simple-webmvc</module>
<module>otel-simple-neo4j</module>
<module>otel-simple-sofarpc</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -216,6 +218,12 @@
<version>${springboot.version}</version>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-all</artifactId>
<version>${sofa.rpc.version}</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 6ee9b91

Please sign in to comment.