From dd8b39a97505bb66c34913928af78a801fd5ff4f Mon Sep 17 00:00:00 2001 From: smallchill Date: Tue, 29 Oct 2019 11:45:10 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=20=E5=A2=9E=E5=8A=A0zipkin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blade-auth/pom.xml | 5 ++ .../config/RedisTokenStoreConfiguration.java | 48 ----------------- .../common/constant/CommonConstant.java | 32 +++++++++++ .../common/launch/LauncherServiceImpl.java | 1 + blade-ops/blade-zipkin/pom.xml | 54 +++++++++++++++++++ .../springblade/zipkin/ZipkinApplication.java | 37 +++++++++++++ .../src/main/resources/bootstrap.yml | 18 +++++++ 7 files changed, 147 insertions(+), 48 deletions(-) delete mode 100644 blade-auth/src/main/java/org/springblade/auth/config/RedisTokenStoreConfiguration.java create mode 100644 blade-ops/blade-zipkin/pom.xml create mode 100644 blade-ops/blade-zipkin/src/main/java/org/springblade/zipkin/ZipkinApplication.java create mode 100644 blade-ops/blade-zipkin/src/main/resources/bootstrap.yml diff --git a/blade-auth/pom.xml b/blade-auth/pom.xml index 11b71f9e..845e33fe 100644 --- a/blade-auth/pom.xml +++ b/blade-auth/pom.xml @@ -73,6 +73,11 @@ jjwt 0.9.1 + + diff --git a/blade-auth/src/main/java/org/springblade/auth/config/RedisTokenStoreConfiguration.java b/blade-auth/src/main/java/org/springblade/auth/config/RedisTokenStoreConfiguration.java deleted file mode 100644 index 61795b03..00000000 --- a/blade-auth/src/main/java/org/springblade/auth/config/RedisTokenStoreConfiguration.java +++ /dev/null @@ -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); - } -} diff --git a/blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java b/blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java index 4f1080cd..4fe16884 100644 --- a/blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java +++ b/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; + } + } + } diff --git a/blade-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java b/blade-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java index 956c3217..16d75912 100644 --- a/blade-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java +++ b/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)); } } diff --git a/blade-ops/blade-zipkin/pom.xml b/blade-ops/blade-zipkin/pom.xml new file mode 100644 index 00000000..cba05241 --- /dev/null +++ b/blade-ops/blade-zipkin/pom.xml @@ -0,0 +1,54 @@ + + + + blade-ops + org.springblade + 2.1.0.RELEASE + + 4.0.0 + + blade-zipkin + ${project.artifactId} + ${bladex.project.version} + jar + + + + + org.springblade + blade-common + + + org.springblade + blade-core-launch + + + org.springblade + blade-core-tool + + + org.springblade + blade-core-cloud + + + + io.zipkin.java + zipkin-server + 2.12.3 + + + log4j-slf4j-impl + org.apache.logging.log4j + + + + + io.zipkin.java + zipkin-autoconfigure-ui + 2.12.3 + + + + diff --git a/blade-ops/blade-zipkin/src/main/java/org/springblade/zipkin/ZipkinApplication.java b/blade-ops/blade-zipkin/src/main/java/org/springblade/zipkin/ZipkinApplication.java new file mode 100644 index 00000000..8c8e0ae6 --- /dev/null +++ b/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); + } + +} diff --git a/blade-ops/blade-zipkin/src/main/resources/bootstrap.yml b/blade-ops/blade-zipkin/src/main/resources/bootstrap.yml new file mode 100644 index 00000000..b5fe10d1 --- /dev/null +++ b/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