git项目地址:https://github.com/blacklau/brave-webmvc-example (forked from openzipkin/brave-webmvc-example ,请忽略README.md说明)
1、pom.xml
4.0.0io.zipkin.bravebrave-webmvc-example1.0-SNAPSHOTwarbrave-webmvc-exampleaExample using Brave to trace RPCs from Spring Web MVChttps://github.com/openzipkin/brave-webmvc-exampleUTF-84.3.3.RELEASE8.1.20.v201609023.16.00.6.9junitjunit4.10testio.zipkin.bravebrave-core-spring${brave.version}io.zipkin.reporterzipkin-sender-okhttp3${zipkin-reporter.version}io.zipkin.reporterzipkin-sender-libthrift${zipkin-reporter.version}io.zipkin.reporterzipkin-sender-kafka08${zipkin-reporter.version}io.zipkin.bravebrave-spring-web-servlet-interceptor${brave.version}io.zipkin.bravebrave-spring-resttemplate-interceptors${brave.version}org.springframeworkspring-core${spring.version}org.springframeworkspring-context${spring.version}org.springframeworkspring-beans${spring.version}org.springframeworkspring-web${spring.version}org.springframeworkspring-webmvc${spring.version}org.eclipse.jettyjetty-server${jetty.version}testorg.eclipse.jettyjetty-webapp${jetty.version}testlog4jlog4j1.2.17org.slf4jslf4j-log4j121.7.21org.slf4jjcl-over-slf4j1.7.21trueorg.apache.maven.pluginsmaven-compiler-plugin2.5.11.61.6truetrueorg.apache.maven.pluginsmaven-failsafe-plugin2.19.1integration-testintegration-testverifyverifyorg.apache.maven.pluginsmaven-war-plugin3.0.0${basedir}/src/main/webapptrue**/index.html${basedir}/src/main/webapp/WEB-INFtrueWEB-INF**/web.xmlWEB-INF/lib/servlet-api-*.jar
2、Brave的初始化及添加拦截器
package brave.webmvc;
import com.github.kristofa.brave.Brave;
import com.github.kristofa.brave.LoggingReporter;
import com.github.kristofa.brave.http.DefaultSpanNameProvider;
import com.github.kristofa.brave.http.SpanNameProvider;
import com.github.kristofa.brave.spring.BraveClientHttpRequestInterceptor;
import com.github.kristofa.brave.spring.ServletHandlerInterceptor;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import zipkin.Span;
import zipkin.reporter.Reporter;
import zipkin.reporter.Sender;
import zipkin.reporter.okhttp3.OkHttpSender;
/**
* This adds tracing configuration to any web mvc controllers or rest template clients. This should
* be configured last.
*/
@Configuration
// import as the interceptors are annotation with javax.inject and not automatically wired
@Import({BraveClientHttpRequestInterceptor.class, ServletHandlerInterceptor.class})
public class WebTracingConfiguration extends WebMvcConfigurerAdapter {
/** 发送器配置 */
@Bean Sender sender() {
return OkHttpSender.create("http://127.0.0.1:9411/api/v1/spans");
//return LibthriftSender.create("127.0.0.1");
// return KafkaSender.create("127.0.0.1:9092");
}
/** 用什么方式显示span信息 */
@Bean Reporter reporter() {
//取消注释,日志打印span信息
//return new LoggingReporter();
return AsyncReporter.builder(sender()).build();
}
@Bean Brave brave() {
return new Brave.Builder("brave-webmvc-example").reporter(reporter()).build();
}
// span命名提供者,默认为http方法.
@Bean SpanNameProvider spanNameProvider() {
return new DefaultSpanNameProvider();
}
@Autowired
private ServletHandlerInterceptor serverInterceptor;
@Autowired
private BraveClientHttpRequestInterceptor clientInterceptor;
@Autowired
private RestTemplate restTemplate;
// 添加rest template拦截器
@PostConstruct
public void init() {
List interceptors =
new ArrayList(restTemplate.getInterceptors());
interceptors.add(clientInterceptor);
restTemplate.setInterceptors(interceptors);
}
// 添加Severlet拦截器
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(serverInterceptor);
}
}
3、springmvc的controller,发布a和b两个服务
package brave.webmvc;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@RestController
@EnableWebMvc
@Configuration
public class ExampleController {
@Bean RestTemplate template() {
return new RestTemplate();
}
@Autowired RestTemplate template;
@RequestMapping("/a")
public String a() throws InterruptedException {
Random random = new Random();
Thread.sleep(random.nextInt(1000));
return template.getForObject("http://localhost:8080/brave-webmvc-example/b", String.class);
}
@RequestMapping("/b")
public String b() throws InterruptedException {
Random random = new Random();
Thread.sleep(random.nextInt(1000));
return "b";
}
}
在客户端访问subversion版本库时出现这个错误:
svnserve.conf:12: Option expected
为什么会出现这个错误呢,就是因为subversion读取配置文件svnserve.conf时,无法识别有前置空格的配置文件,如### This file controls the configuration of the svnserve daemon, if you##
什么是Akka
Message-Driven Runtime is the Foundation to Reactive Applications
In Akka, your business logic is driven through message-based communication patterns that are independent of physical locatio
zabbix_api网上比较多的写法是python或curl。上次我用java--http://bossr.iteye.com/blog/2195679,这次用perl。for example: #!/usr/bin/perl
use 5.010 ;
use strict ;
use warnings ;
use JSON :: RPC :: Client ;
use
package com.test;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class TestMap {
public static v
MySQL server has gone away 问题解决方法,需要的朋友可以参考下。
应用程序(比如PHP)长时间的执行批量的MYSQL语句。执行一个SQL,但SQL语句过大或者语句中含有BLOB或者longblob字段。比如,图片数据的处理。都容易引起MySQL server has gone away。 今天遇到类似的情景,MySQL只是冷冷的说:MySQL server h
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml&