Commit a81cfd80 authored by 技术部-任文超's avatar 技术部-任文超

完成zipkin接入

parent b20fe017
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<parent> <parent>
<groupId>cn.quantgroup</groupId> <groupId>cn.quantgroup</groupId>
<artifactId>commons-parent</artifactId> <artifactId>commons-parent</artifactId>
<version>0.2.3</version> <version>0.2.4</version>
</parent> </parent>
<properties> <properties>
...@@ -272,10 +272,6 @@ ...@@ -272,10 +272,6 @@
<groupId>cn.quantgroup</groupId> <groupId>cn.quantgroup</groupId>
<artifactId>shutdown-spring-boot-starter</artifactId> <artifactId>shutdown-spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>idgenerator-spring-boot-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>cn.quantgroup</groupId> <groupId>cn.quantgroup</groupId>
<artifactId>brave-spring-boot-starter</artifactId> <artifactId>brave-spring-boot-starter</artifactId>
......
package cn.quantgroup.xyqb; package cn.quantgroup.xyqb;
import cn.quantgroup.tech.shutdown.DefaultSignalHandler;
import com.weibo.api.motan.common.MotanConstants; import com.weibo.api.motan.common.MotanConstants;
import com.weibo.api.motan.util.MotanSwitcherUtil; import com.weibo.api.motan.util.MotanSwitcherUtil;
import io.sentry.Sentry;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import sun.misc.Signal;
/** /**
* @author Anonymous * @author Anonymous
...@@ -24,9 +19,9 @@ import sun.misc.Signal; ...@@ -24,9 +19,9 @@ import sun.misc.Signal;
* -Denv=dev -Didc=k8s -Dlogging.config=classpath:logback-dev.xml -DNAMESPACE=xxx -Dserver.port=8099 * -Denv=dev -Didc=k8s -Dlogging.config=classpath:logback-dev.xml -DNAMESPACE=xxx -Dserver.port=8099
*/ */
@Slf4j @Slf4j
@EnableAsync @ComponentScan(basePackages = {"cn.quantgroup.sms", "cn.quantgroup.xyqb"})
@EnableCaching @EnableCaching
@ComponentScan(basePackages = {"cn.quantgroup.sms", "cn.quantgroup.xyqb", "cn.quantgroup.tech"}) @EnableAsync
@EnableAspectJAutoProxy @EnableAspectJAutoProxy
@SpringBootApplication @SpringBootApplication
public class Bootstrap { public class Bootstrap {
...@@ -40,15 +35,7 @@ public class Bootstrap { ...@@ -40,15 +35,7 @@ public class Bootstrap {
log.info("注册zookeeper成功"); log.info("注册zookeeper成功");
} }
}); });
springApplication.setRegisterShutdownHook(true); springApplication.run(args);
ConfigurableApplicationContext run = springApplication.run(args);
log.info("server start...");
// 启用平滑退出功能
Signal.handle(new Signal("INT"), new DefaultSignalHandler(run));
// 异常log捕获
Environment environment = run.getBean(Environment.class);
String dsn = environment.getProperty("dsn");
Sentry.init(dsn);
} }
} }
package cn.quantgroup.xyqb.config.http; package cn.quantgroup.xyqb.config.http;
import cn.quantgroup.tech.brave.service.ITechHttpClient;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
...@@ -35,6 +36,7 @@ import org.springframework.format.support.FormattingConversionService; ...@@ -35,6 +36,7 @@ import org.springframework.format.support.FormattingConversionService;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.filter.CharacterEncodingFilter;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
...@@ -46,6 +48,9 @@ import java.text.SimpleDateFormat; ...@@ -46,6 +48,9 @@ import java.text.SimpleDateFormat;
*/ */
@Configuration @Configuration
public class HttpConfig { public class HttpConfig {
//注入brave-spring-boot-starter提供的techHttpClient
@Resource
private ITechHttpClient techHttpClient;
@Bean @Bean
public FilterRegistrationBean filterRegistrationBean() { public FilterRegistrationBean filterRegistrationBean() {
...@@ -137,7 +142,7 @@ public class HttpConfig { ...@@ -137,7 +142,7 @@ public class HttpConfig {
ConnectionKeepAliveStrategy keepAliveStrategy = new DefaultConnectionKeepAliveStrategy(); ConnectionKeepAliveStrategy keepAliveStrategy = new DefaultConnectionKeepAliveStrategy();
// httpclient // httpclient
return HttpClients.custom() return techHttpClient.createHttpClientBuilder()
.setConnectionManager(connectionManager) .setConnectionManager(connectionManager)
.setRetryHandler(retryHandler) .setRetryHandler(retryHandler)
.setKeepAliveStrategy(keepAliveStrategy) .setKeepAliveStrategy(keepAliveStrategy)
......
package cn.quantgroup.xyqb.config.mq; package cn.quantgroup.xyqb.config.mq;
import cn.quantgroup.tech.brave.service.ITechRabbitBuilder;
import org.springframework.amqp.core.*; import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory;
...@@ -11,6 +12,8 @@ import org.springframework.context.annotation.Bean; ...@@ -11,6 +12,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import javax.annotation.Resource;
/** /**
* //马甲包 xuran * //马甲包 xuran
*/ */
...@@ -32,8 +35,9 @@ public class LoanVestMQConfig { ...@@ -32,8 +35,9 @@ public class LoanVestMQConfig {
private String password; private String password;
@Value("${loanvest.rabbitmq.connection.virtual-host}") @Value("${loanvest.rabbitmq.connection.virtual-host}")
private String virtualHost; private String virtualHost;
//@Value("${loanvest.rabbitmq.stateMsgQueue}")
//private String stateQueueName; @Resource
private ITechRabbitBuilder techRabbitBuilder;
@Primary @Primary
@Bean(name = "vestFactory") @Bean(name = "vestFactory")
...@@ -80,7 +84,7 @@ public class LoanVestMQConfig { ...@@ -80,7 +84,7 @@ public class LoanVestMQConfig {
@Primary @Primary
@Bean(name = "rabbitTemplate") @Bean(name = "rabbitTemplate")
public RabbitTemplate loanVestTemplate(@Qualifier("vestFactory") ConnectionFactory vestFactory) { public RabbitTemplate loanVestTemplate(@Qualifier("vestFactory") ConnectionFactory vestFactory) {
RabbitTemplate template = new RabbitTemplate(vestFactory); RabbitTemplate template = techRabbitBuilder.createRabbitTemplate(vestFactory);
template.setExchange(loanVestExchange); template.setExchange(loanVestExchange);
return template; return template;
} }
......
package cn.quantgroup.xyqb.config.mq; package cn.quantgroup.xyqb.config.mq;
import cn.quantgroup.tech.brave.service.ITechRabbitBuilder;
import org.springframework.amqp.core.*; import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory;
...@@ -10,6 +11,8 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -10,6 +11,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
/** /**
* Created by xuran on 2017/9/7. * Created by xuran on 2017/9/7.
*/ */
...@@ -37,6 +40,9 @@ public class RegisterMqConfig { ...@@ -37,6 +40,9 @@ public class RegisterMqConfig {
@Value("${register.rabbitmq.connection.virtual-host}") @Value("${register.rabbitmq.connection.virtual-host}")
private String virtualHost; private String virtualHost;
@Resource
private ITechRabbitBuilder techRabbitBuilder;
@Bean(name = "registerMqFactory") @Bean(name = "registerMqFactory")
public ConnectionFactory registerMqFactory() { public ConnectionFactory registerMqFactory() {
...@@ -77,7 +83,7 @@ public class RegisterMqConfig { ...@@ -77,7 +83,7 @@ public class RegisterMqConfig {
@Bean(name = "registerRabbitTemplate") @Bean(name = "registerRabbitTemplate")
public RabbitTemplate registerTemplate(@Qualifier("registerMqFactory") ConnectionFactory registerMqFactory) { public RabbitTemplate registerTemplate(@Qualifier("registerMqFactory") ConnectionFactory registerMqFactory) {
RabbitTemplate template = new RabbitTemplate(registerMqFactory); RabbitTemplate template = techRabbitBuilder.createRabbitTemplate(registerMqFactory);
template.setExchange(registerMqExchange); template.setExchange(registerMqExchange);
return template; return template;
} }
...@@ -103,7 +109,7 @@ public class RegisterMqConfig { ...@@ -103,7 +109,7 @@ public class RegisterMqConfig {
@Bean(name = "registerRabbitTemplate4Gdt") @Bean(name = "registerRabbitTemplate4Gdt")
public RabbitTemplate registerTemplate4Gdt(@Qualifier("registerMqFactory") ConnectionFactory registerMqFactory) { public RabbitTemplate registerTemplate4Gdt(@Qualifier("registerMqFactory") ConnectionFactory registerMqFactory) {
RabbitTemplate template = new RabbitTemplate(registerMqFactory); RabbitTemplate template = techRabbitBuilder.createRabbitTemplate(registerMqFactory);
template.setExchange(exchange4Gdt); template.setExchange(exchange4Gdt);
return template; return template;
} }
......
package cn.quantgroup.xyqb.config.sentry; package cn.quantgroup.xyqb.config.sentry;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import io.sentry.Sentry;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.HandlerExceptionResolver;
import javax.annotation.PostConstruct;
/** /**
* @author xufei on 2017/12/27. * 初始化Sentry配置
* @author renwc
* @date 2018-05-22
*/ */
@Controller @Configuration
@EnableAutoConfiguration
@SpringBootApplication
public class SentryConfig { public class SentryConfig {
@Value("${dsn}")
private String dsn;
@Bean @Bean
public HandlerExceptionResolver sentryExceptionResolver() { public HandlerExceptionResolver sentryExceptionResolver() {
return new io.sentry.spring.SentryExceptionResolver(); return new io.sentry.spring.SentryExceptionResolver();
...@@ -23,4 +29,9 @@ public class SentryConfig { ...@@ -23,4 +29,9 @@ public class SentryConfig {
public ServletContextInitializer sentryServletContextInitializer() { public ServletContextInitializer sentryServletContextInitializer() {
return new io.sentry.spring.SentryServletContextInitializer(); return new io.sentry.spring.SentryServletContextInitializer();
} }
@PostConstruct
public void initSentry(){
Sentry.init(dsn);
}
} }
package cn.quantgroup.xyqb.service.http.impl; package cn.quantgroup.xyqb.service.http.impl;
import cn.quantgroup.tech.brave.service.ITechHttpClient;
import cn.quantgroup.xyqb.service.http.IHttpService; import cn.quantgroup.xyqb.service.http.IHttpService;
import cn.quantgroup.xyqb.util.Utils; import cn.quantgroup.xyqb.util.Utils;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
...@@ -43,6 +44,7 @@ import org.slf4j.Logger; ...@@ -43,6 +44,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
...@@ -62,6 +64,9 @@ public class HttpServiceImpl implements IHttpService { ...@@ -62,6 +64,9 @@ public class HttpServiceImpl implements IHttpService {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpServiceImpl.class); private static final Logger LOGGER = LoggerFactory.getLogger(HttpServiceImpl.class);
private static final int TIME_OUT = 60 * 1000; // 超时时间 private static final int TIME_OUT = 60 * 1000; // 超时时间
//注入brave-spring-boot-starter提供的techHttpClient
@Resource
private ITechHttpClient techHttpClient;
@Override @Override
public String get(String uri) { public String get(String uri) {
...@@ -191,7 +196,7 @@ public class HttpServiceImpl implements IHttpService { ...@@ -191,7 +196,7 @@ public class HttpServiceImpl implements IHttpService {
ConnectionKeepAliveStrategy keepAliveStrategy = new DefaultConnectionKeepAliveStrategy(); ConnectionKeepAliveStrategy keepAliveStrategy = new DefaultConnectionKeepAliveStrategy();
// httpclient // httpclient
return HttpClients.custom() return techHttpClient.createHttpClientBuilder()
.setConnectionManager(connectionManager) .setConnectionManager(connectionManager)
.setRetryHandler(retryHandler) .setRetryHandler(retryHandler)
.setKeepAliveStrategy(keepAliveStrategy) .setKeepAliveStrategy(keepAliveStrategy)
......
...@@ -23,7 +23,7 @@ public class LoanVestMQServiceImpl implements IVestService { ...@@ -23,7 +23,7 @@ public class LoanVestMQServiceImpl implements IVestService {
@Resource @Resource
@Qualifier("rabbitTemplate") @Qualifier("rabbitTemplate")
private RabbitTemplate loanVestRabbitTemplate; private RabbitTemplate rabbitTemplate;
@Resource @Resource
@Qualifier(value = "loanVestQueue") @Qualifier(value = "loanVestQueue")
...@@ -42,7 +42,7 @@ public class LoanVestMQServiceImpl implements IVestService { ...@@ -42,7 +42,7 @@ public class LoanVestMQServiceImpl implements IVestService {
} }
LOGGER.info("用户登陆统计发送,message={}", message); LOGGER.info("用户登陆统计发送,message={}", message);
String msg = JSONObject.toJSONString(message); String msg = JSONObject.toJSONString(message);
loanVestRabbitTemplate.convertAndSend("statistics-user", msg); rabbitTemplate.convertAndSend("statistics-user", msg);
LOGGER.info("用户登陆统计成功,message={}", msg); LOGGER.info("用户登陆统计成功,message={}", msg);
} }
......
package login; package login;
import cn.quantgroup.tech.brave.service.ITechHttpClient;
import cn.quantgroup.xyqb.Bootstrap; import cn.quantgroup.xyqb.Bootstrap;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.controller.external.user.InnerController; import cn.quantgroup.xyqb.controller.external.user.InnerController;
...@@ -44,6 +45,9 @@ public class TestUserLogin { ...@@ -44,6 +45,9 @@ public class TestUserLogin {
@Resource @Resource
private InnerController innerController; private InnerController innerController;
//注入brave-spring-boot-starter提供的techHttpClient
@Resource
private ITechHttpClient techHttpClient;
@Test @Test
public void testBull() { public void testBull() {
...@@ -82,8 +86,7 @@ public class TestUserLogin { ...@@ -82,8 +86,7 @@ public class TestUserLogin {
String token = authBean.getToken(); String token = authBean.getToken();
System.out.println("user token:" + token); System.out.println("user token:" + token);
//用获取到的token请求xyqb的receive_token //用获取到的token请求xyqb的receive_token
CloseableHttpClient httpClient = techHttpClient.createHttpClientBuilder().build();
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost post = new HttpPost("http://localhost:9004/ex/login/receive_token"); HttpPost post = new HttpPost("http://localhost:9004/ex/login/receive_token");
List<NameValuePair> pairList = new ArrayList<>(); List<NameValuePair> pairList = new ArrayList<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment