Skip to content

Commit c7e5ff9

Browse files
committed
update
1 parent cc35efd commit c7e5ff9

File tree

26 files changed

+793
-234
lines changed

26 files changed

+793
-234
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@
9090
## 学习资源
9191

9292
- Java 经典书籍
93-
- [《Effective Java 中文版》](https://union-click.jd.com/jdc?d=S003h8) - 本书介绍了在 Java 编程中 78 条极具实用价值的经验规则,这些经验规则涵盖了大多数开发人员每天所面临的问题的解决方案。同推荐《重构 : 改善既有代码的设计》、《代码整洁之道》、《代码大全》,有一定的内容重叠。
94-
- [《Java 并发编程实战》](https://union-click.jd.com/jdc?d=x2yrwq) - 本书深入浅出地介绍了 Java 线程和并发,是一本完美的 Java 并发参考手册。
95-
- [《深入理解 Java 虚拟机:JVM 高级特性与最佳实践](https://union-click.jd.com/jdc?d=Wa6dWb) - 不去了解 JVM 的工程师,和咸鱼有什么区
96-
- [《Maven 实战》](https://union-click.jd.com/jdc?d=hNj9Lu) - 国内最权威的 Maven 专家的力作,唯一一本哦!
93+
- [《Effective Java 中文版》](https://item.jd.com/12507084.html) - 本书介绍了在 Java 编程中 78 条极具实用价值的经验规则,这些经验规则涵盖了大多数开发人员每天所面临的问题的解决方案。同推荐《重构 : 改善既有代码的设计》、《代码整洁之道》、《代码大全》,有一定的内容重叠。
94+
- [《Java 并发编程实战》](https://item.jd.com/10922250.html) - 本书深入浅出地介绍了 Java 线程和并发,是一本完美的 Java 并发参考手册。
95+
- [《深入理解 Java 虚拟机》](https://item.jd.com/11252778.html) - 不去了解 JVM 的工程师,和咸鱼有什么区
96+
- [《Maven 实战》](https://item.jd.com/10476794.html) - 国内最权威的 Maven 专家的力作,唯一一本哦!
9797
- 其他领域书籍
98-
- [《Redis 设计与实现》](https://union-click.jd.com/jdc?d=6L6sMX) - 系统而全面地描述了 Redis 内部运行机制。图示丰富,描述清晰,并给出大量参考信息,是 NoSQL 数据库开发人员案头必备。
99-
- [《鸟哥的 Linux 私房菜 (基础学习篇)》](https://union-click.jd.com/jdc?d=yB7dwu) - 本书是最具知名度的 Linux 入门书《鸟哥的 Linux 私房菜基础学习篇》的最新版,全面而详细地介绍了 Linux 操作系统。内容非常全面,建议挑选和自己实际工作相关度较高的,其他部分有需要再阅读。
100-
- [《Head First 设计模式》](https://union-click.jd.com/jdc?d=HYyuyM) - 《Head First 设计模式》(中文版)共有 14 章,每章都介绍了几个设计模式,完整地涵盖了四人组版本全部 23 个设计模式。
101-
- [《HTTP 权威指南》](https://union-click.jd.com/jdc?d=TgCRBb) - 本书尝试着将 HTTP 中一些互相关联且常被误解的规则梳理清楚,并编写了一系列基于各种主题的章节,对 HTTP 各方面的特性进行了介绍。纵观全书,对 HTTP“为什么”这样做进行了详细的解释,而不仅仅停留在它是“怎么做”的。
102-
- [《TCP/IP 详解 系列》](https://union-click.jd.com/jdc?d=5uHlXS) - 完整而详细的 TCP/IP 协议指南。针对任何希望理解 TCP/IP 协议是如何实现的读者设计。
103-
- [《剑指 Offer:名企面试官精讲典型编程题》](https://union-click.jd.com/jdc?d=wnrKQh) - 剖析了 80 个典型的编程面试题,系统整理基础知识、代码质量、解题思路、优化效率和综合能力这 5 个面试要点。
98+
- [《Redis 设计与实现》](https://item.jd.com/11486101.html) - 系统而全面地描述了 Redis 内部运行机制。图示丰富,描述清晰,并给出大量参考信息,是 NoSQL 数据库开发人员案头必备。
99+
- [《鸟哥的 Linux 私房菜 (基础学习篇)》](https://item.jd.com/12443890.html) - 本书是最具知名度的 Linux 入门书《鸟哥的 Linux 私房菜基础学习篇》的最新版,全面而详细地介绍了 Linux 操作系统。内容非常全面,建议挑选和自己实际工作相关度较高的,其他部分有需要再阅读。
100+
- [《Head First 设计模式》](https://item.jd.com/10100236.html) - 《Head First 设计模式》(中文版)共有 14 章,每章都介绍了几个设计模式,完整地涵盖了四人组版本全部 23 个设计模式。
101+
- [《HTTP 权威指南》](https://item.jd.com/11056556.html) - 本书尝试着将 HTTP 中一些互相关联且常被误解的规则梳理清楚,并编写了一系列基于各种主题的章节,对 HTTP 各方面的特性进行了介绍。纵观全书,对 HTTP“为什么”这样做进行了详细的解释,而不仅仅停留在它是“怎么做”的。
102+
- [《TCP/IP 详解 系列》](https://item.jd.com/11966296.html) - 完整而详细的 TCP/IP 协议指南。针对任何希望理解 TCP/IP 协议是如何实现的读者设计。
103+
- [《剑指 Offer:名企面试官精讲典型编程题》](https://item.jd.com/12163054.html) - 剖析了 80 个典型的编程面试题,系统整理基础知识、代码质量、解题思路、优化效率和综合能力这 5 个面试要点。
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 监控工具示例
2+
3+
## Zipkin
4+
5+
> 搬迁 https://github.com/openzipkin/brave-webmvc-example 示例。
6+
>
7+
8+
使用方法:
9+
10+
```
11+
mvn jetty:run -Pfrontend
12+
mvn jetty:run -Pbackend
13+
```
14+
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>io.github.dunwu.javatool</groupId>
7+
<artifactId>javatool-zipkin-spring</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>war</packaging>
10+
<name>${project.artifactId}</name>
11+
<description>Java distributed tracing implementation compatible with Zipkin backend services.</description>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>1.7</maven.compiler.source>
16+
<maven.compiler.target>1.7</maven.compiler.target>
17+
18+
<spring.version>4.3.26.RELEASE</spring.version>
19+
<log4j.version>2.13.0</log4j.version>
20+
<brave.version>5.10.1</brave.version>
21+
</properties>
22+
23+
<dependencyManagement>
24+
<dependencies>
25+
<dependency>
26+
<groupId>io.zipkin.brave</groupId>
27+
<artifactId>brave-bom</artifactId>
28+
<version>${brave.version}</version>
29+
<type>pom</type>
30+
<scope>import</scope>
31+
</dependency>
32+
</dependencies>
33+
</dependencyManagement>
34+
35+
<dependencies>
36+
<dependency>
37+
<groupId>javax.servlet</groupId>
38+
<artifactId>javax.servlet-api</artifactId>
39+
<version>3.1.0</version>
40+
<scope>provided</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework</groupId>
44+
<artifactId>spring-webmvc</artifactId>
45+
<version>${spring.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework</groupId>
49+
<artifactId>spring-web</artifactId>
50+
<version>${spring.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.apache.httpcomponents</groupId>
54+
<artifactId>httpclient</artifactId>
55+
<version>4.5.11</version>
56+
</dependency>
57+
58+
<!-- Adds the MVC class and method names to server spans -->
59+
<dependency>
60+
<groupId>io.zipkin.brave</groupId>
61+
<artifactId>brave-instrumentation-spring-webmvc</artifactId>
62+
</dependency>
63+
<!-- Instruments the underlying HttpClient requests that call the backend -->
64+
<dependency>
65+
<groupId>io.zipkin.brave</groupId>
66+
<artifactId>brave-instrumentation-httpclient</artifactId>
67+
</dependency>
68+
69+
<!-- Integrates so you can use log patterns like %X{traceId}/%X{spanId} -->
70+
<dependency>
71+
<groupId>org.apache.logging.log4j</groupId>
72+
<artifactId>log4j-core</artifactId>
73+
<version>${log4j.version}</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.apache.logging.log4j</groupId>
77+
<artifactId>log4j-jul</artifactId>
78+
<version>${log4j.version}</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.apache.logging.log4j</groupId>
82+
<artifactId>log4j-jcl</artifactId>
83+
<version>${log4j.version}</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.apache.logging.log4j</groupId>
87+
<artifactId>log4j-slf4j-impl</artifactId>
88+
<version>${log4j.version}</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>io.zipkin.brave</groupId>
92+
<artifactId>brave-context-log4j2</artifactId>
93+
</dependency>
94+
95+
<!-- The below are needed to report traces to http://localhost:9411/api/v2/spans -->
96+
<dependency>
97+
<groupId>io.zipkin.brave</groupId>
98+
<artifactId>brave-spring-beans</artifactId>
99+
</dependency>
100+
<dependency>
101+
<groupId>io.zipkin.brave</groupId>
102+
<artifactId>brave</artifactId>
103+
</dependency>
104+
<dependency>
105+
<groupId>io.zipkin.reporter2</groupId>
106+
<artifactId>zipkin-sender-okhttp3</artifactId>
107+
</dependency>
108+
</dependencies>
109+
110+
<build>
111+
<plugins>
112+
<plugin>
113+
<artifactId>maven-compiler-plugin</artifactId>
114+
<version>3.8.1</version>
115+
</plugin>
116+
117+
<plugin>
118+
<artifactId>maven-enforcer-plugin</artifactId>
119+
<version>3.0.0-M3</version>
120+
<executions>
121+
<execution>
122+
<id>enforce-java</id>
123+
<goals>
124+
<goal>enforce</goal>
125+
</goals>
126+
<configuration>
127+
<rules>
128+
<requireJavaVersion>
129+
<!-- prevent a compile bug accessing CrossOrigin -->
130+
<version>[1.7.0_80,)</version>
131+
</requireJavaVersion>
132+
</rules>
133+
</configuration>
134+
</execution>
135+
</executions>
136+
</plugin>
137+
138+
<plugin>
139+
<artifactId>maven-war-plugin</artifactId>
140+
<version>3.2.3</version>
141+
<configuration>
142+
<failOnMissingWebXml>false</failOnMissingWebXml>
143+
<packagingExcludes>WEB-INF/lib/servlet-api-*.jar</packagingExcludes>
144+
</configuration>
145+
</plugin>
146+
</plugins>
147+
<pluginManagement>
148+
<plugins>
149+
<plugin>
150+
<groupId>org.eclipse.jetty</groupId>
151+
<artifactId>jetty-maven-plugin</artifactId>
152+
<version>9.4.26.v20200117</version>
153+
</plugin>
154+
</plugins>
155+
</pluginManagement>
156+
</build>
157+
158+
<profiles>
159+
<profile>
160+
<id>frontend</id>
161+
<build>
162+
<plugins>
163+
<plugin>
164+
<groupId>org.eclipse.jetty</groupId>
165+
<artifactId>jetty-maven-plugin</artifactId>
166+
<configuration>
167+
<httpConnector>
168+
<port>8081</port>
169+
</httpConnector>
170+
<systemProperties>
171+
<systemProperty>
172+
<name>zipkin.service</name>
173+
<value>frontend</value>
174+
</systemProperty>
175+
</systemProperties>
176+
</configuration>
177+
</plugin>
178+
</plugins>
179+
</build>
180+
</profile>
181+
<profile>
182+
<id>backend</id>
183+
<build>
184+
<plugins>
185+
<plugin>
186+
<groupId>org.eclipse.jetty</groupId>
187+
<artifactId>jetty-maven-plugin</artifactId>
188+
<configuration>
189+
<httpConnector>
190+
<port>9000</port>
191+
</httpConnector>
192+
<systemProperties>
193+
<systemProperty>
194+
<name>zipkin.service</name>
195+
<value>backend</value>
196+
</systemProperty>
197+
</systemProperties>
198+
</configuration>
199+
</plugin>
200+
</plugins>
201+
</build>
202+
</profile>
203+
</profiles>
204+
205+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.github.dunwu.javatool.monitor.zipkin;
2+
3+
import org.apache.http.client.HttpClient;
4+
import org.apache.http.impl.client.HttpClients;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
8+
import org.springframework.web.client.RestTemplate;
9+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
10+
11+
/** The application is simple, it only uses Web MVC and a {@linkplain RestTemplate}. */
12+
@EnableWebMvc
13+
public class AppConfiguration {
14+
@Autowired(required = false)
15+
HttpClient httpClient;
16+
17+
@Bean RestTemplate restTemplate() {
18+
HttpClient httpClient = this.httpClient;
19+
if (httpClient == null) httpClient = HttpClients.createDefault();
20+
return new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.dunwu.javatool.monitor.zipkin;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.bind.annotation.RequestHeader;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
8+
9+
import java.util.Date;
10+
11+
@Configuration
12+
@EnableWebMvc
13+
@RestController
14+
public class Backend {
15+
16+
@RequestMapping("/api")
17+
public String printDate(@RequestHeader(name = "user-name", required = false) String username) {
18+
if (username != null) {
19+
return new Date().toString() + " " + username;
20+
}
21+
return new Date().toString();
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.github.dunwu.javatool.monitor.zipkin;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.web.bind.annotation.CrossOrigin;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
import org.springframework.web.client.RestTemplate;
9+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
10+
11+
@EnableWebMvc
12+
@RestController
13+
@Configuration
14+
@CrossOrigin // So that javascript can be hosted elsewhere
15+
public class Frontend {
16+
@Autowired RestTemplate restTemplate;
17+
18+
@RequestMapping("/") public String callBackend() {
19+
return restTemplate.getForObject("http://localhost:9000/api", String.class);
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.github.dunwu.javatool.monitor.zipkin;
2+
3+
import brave.spring.webmvc.DelegatingTracingFilter;
4+
import org.springframework.web.SpringServletContainerInitializer;
5+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
6+
7+
import javax.servlet.Filter;
8+
9+
/** Indirectly invoked by {@link SpringServletContainerInitializer} in a Servlet 3+ container */
10+
public class Initializer extends AbstractAnnotationConfigDispatcherServletInitializer {
11+
12+
@Override protected String[] getServletMappings() {
13+
return new String[] {"/"};
14+
}
15+
16+
@Override protected Class<?>[] getRootConfigClasses() {
17+
return new Class[] { TracingConfiguration.class, AppConfiguration.class};
18+
}
19+
20+
/** Ensures tracing is setup for all HTTP requests. */
21+
@Override protected Filter[] getServletFilters() {
22+
return new Filter[] {new DelegatingTracingFilter()};
23+
}
24+
25+
@Override protected Class<?>[] getServletConfigClasses() {
26+
return new Class[] { Frontend.class, Backend.class};
27+
}
28+
}

0 commit comments

Comments
 (0)