Browse Source

🎉 增加zipkin

test
smallchill 5 years ago
parent
commit
dd8b39a975
  1. 5
      blade-auth/pom.xml
  2. 48
      blade-auth/src/main/java/org/springblade/auth/config/RedisTokenStoreConfiguration.java
  3. 32
      blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java
  4. 1
      blade-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java
  5. 54
      blade-ops/blade-zipkin/pom.xml
  6. 37
      blade-ops/blade-zipkin/src/main/java/org/springblade/zipkin/ZipkinApplication.java
  7. 18
      blade-ops/blade-zipkin/src/main/resources/bootstrap.yml

5
blade-auth/pom.xml

@ -73,6 +73,11 @@
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<!--Zipkin-->
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>-->
</dependencies>
<build>

48
blade-auth/src/main/java/org/springblade/auth/config/RedisTokenStoreConfiguration.java

@ -1,48 +0,0 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.auth.config;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
/**
* Redis TokenStore
*
* @author Chill
*/
@Configuration
@AllArgsConstructor
public class RedisTokenStoreConfiguration {
/**
* redis连接工厂
*/
private RedisConnectionFactory redisConnectionFactory;
/**
* 用于存放token
*/
@Bean
@ConditionalOnProperty(prefix = "blade.security.oauth2", name = "storeType", havingValue = "redis")
public TokenStore redisTokenStore() {
return new RedisTokenStore(redisConnectionFactory);
}
}

32
blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java

@ -55,6 +55,21 @@ public interface CommonConstant {
*/
String SENTINEL_TEST_ADDR = "172.30.0.58:8858";
/**
* zipkin dev 地址
*/
String ZIPKIN_DEV_ADDR = "http://127.0.0.1:9411";
/**
* zipkin prod 地址
*/
String ZIPKIN_PROD_ADDR = "http://172.30.0.58:9411";
/**
* zipkin test 地址
*/
String ZIPKIN_TEST_ADDR = "http://172.30.0.58:9411";
/**
* sword 系统名
*/
@ -120,4 +135,21 @@ public interface CommonConstant {
}
}
/**
* 动态获取zipkin地址
*
* @param profile 环境变量
* @return addr
*/
static String zipkinAddr(String profile) {
switch (profile) {
case (AppConstant.PROD_CODE):
return ZIPKIN_PROD_ADDR;
case (AppConstant.TEST_CODE):
return ZIPKIN_TEST_ADDR;
default:
return ZIPKIN_DEV_ADDR;
}
}
}

1
blade-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java

@ -38,6 +38,7 @@ public class LauncherServiceImpl implements LauncherService {
PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.server-addr", CommonConstant.nacosAddr(profile));
PropsUtil.setProperty(props, "spring.cloud.nacos.config.server-addr", CommonConstant.nacosAddr(profile));
PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", CommonConstant.sentinelAddr(profile));
PropsUtil.setProperty(props, "spring.zipkin.base-url", CommonConstant.zipkinAddr(profile));
}
}

54
blade-ops/blade-zipkin/pom.xml

@ -0,0 +1,54 @@
<?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>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>2.1.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-zipkin</artifactId>
<name>${project.artifactId}</name>
<version>${bladex.project.version}</version>
<packaging>jar</packaging>
<dependencies>
<!--Blade-->
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-common</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-launch</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-tool</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-cloud</artifactId>
</dependency>
<!--Zipkin-->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.12.3</version>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>2.12.3</version>
</dependency>
</dependencies>
</project>

37
blade-ops/blade-zipkin/src/main/java/org/springblade/zipkin/ZipkinApplication.java

@ -0,0 +1,37 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.zipkin;
import org.springblade.core.launch.BladeApplication;
import org.springblade.core.launch.constant.AppConstant;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import zipkin2.server.internal.EnableZipkinServer;
/**
* Zipkin启动器
*
* @author Chill
*/
@EnableZipkinServer
@SpringBootApplication
public class ZipkinApplication {
public static void main(String[] args) {
BladeApplication.run(AppConstant.APPLICATION_ZIPKIN_NAME, ZipkinApplication.class, args);
}
}

18
blade-ops/blade-zipkin/src/main/resources/bootstrap.yml

@ -0,0 +1,18 @@
server:
port: 9411
undertow:
# 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
io-threads: 4
# 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
worker-threads: 20
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
buffer-size: 1024
# 是否分配的直接内存
direct-buffers: true
#zipkin启动报错无法访问的解决方法
management:
metrics:
web:
server:
auto-time-requests: false
Loading…
Cancel
Save