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

完成zipkin接入

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