-
Notifications
You must be signed in to change notification settings - Fork 47
bugfix: fix trpc-core TrpcMDCAdapter class cause spring-boot web error #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
76485e8
bugfix: fix trpc-core TrpcMDCAdapter class cause spring-boot web error
riverzzz f759c7f
bugfix: fix trpc-core TrpcMDCAdapter class cause spring-boot web error
riverzzz 28cb5c5
bugfix: fix trpc-core TrpcMDCAdapter class cause spring-boot web error
riverzzz b26ab32
bugfix: fix trpc-core TrpcMDCAdapter class cause spring-boot web error
riverzzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
trpc-core/src/main/java/com/tencent/trpc/core/utils/ConfigUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.tencent.trpc.core.utils; | ||
|
|
||
| import com.tencent.trpc.core.common.TRpcSystemProperties; | ||
| import com.tencent.trpc.core.common.config.GlobalConfig; | ||
| import com.tencent.trpc.core.common.config.constant.ConfigConstants; | ||
| import com.tencent.trpc.core.logger.Logger; | ||
| import com.tencent.trpc.core.logger.LoggerFactory; | ||
| import org.apache.commons.collections4.MapUtils; | ||
| import org.apache.commons.lang3.ObjectUtils; | ||
|
|
||
| import java.io.FileInputStream; | ||
| import java.util.Map; | ||
|
|
||
|
|
||
| /** | ||
| * @author jiaxxzhang | ||
| * @project trpc-java | ||
| * @description 静态加载配置工具类 | ||
| * @date 2024/4/3 14:20:14 | ||
| */ | ||
| public class ConfigUtils { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(ConfigUtils.class); | ||
|
|
||
| public static final String DEFAULT_YAML_CONFIG_FILE_NAME = "trpc_java.yaml"; | ||
|
|
||
| /** | ||
| * 静态加载全局配置 | ||
| * | ||
| * @return | ||
| */ | ||
| public static GlobalConfig loadGlobalConfig() { | ||
| String confPath = TRpcSystemProperties.getProperties(TRpcSystemProperties.CONFIG_PATH); | ||
| Map<String, Object> config = null; | ||
| try { | ||
| if (StringUtils.isEmpty(confPath)) { | ||
| logger.warn("warning!!, not set properties [" + TRpcSystemProperties.CONFIG_PATH | ||
| + "], we will use classpath:" + DEFAULT_YAML_CONFIG_FILE_NAME + ""); | ||
| if (ObjectUtils.isNotEmpty(YamlParser.class.getClassLoader().getResourceAsStream(DEFAULT_YAML_CONFIG_FILE_NAME))){ | ||
| config = (Map<String, Object>) YamlParser.parseAsFromClassPath(DEFAULT_YAML_CONFIG_FILE_NAME, Map.class).get(ConfigConstants.GLOBAL); | ||
| } | ||
| } else { | ||
| config = (Map<String, Object>) YamlParser.parseAs(new FileInputStream(confPath), Map.class).get(ConfigConstants.GLOBAL); | ||
| } | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| GlobalConfig globalConfig = new GlobalConfig(); | ||
| if(MapUtils.isNotEmpty(config)){ | ||
| BinderUtils.bind(globalConfig, config); | ||
| BinderUtils.bind(BinderUtils.UNDERSCORES_TO_UPPERCASE, globalConfig, config, | ||
| ConfigConstants.ENABLE_SET, o -> "Y".equalsIgnoreCase(String.valueOf(o))); | ||
| } | ||
| return globalConfig; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| global: #全局配置 | ||
| namespace: test_namespace #环境类型,分正式环境和非正式环境两种类型 | ||
| env_name: test_env_name #环境名称,非正式环境下多环境的名称 | ||
| container_name: test_container_name #节点容器名 | ||
| enable_set: Y | ||
| full_set_name: a.b.c #set分组信息 | ||
| ext: | ||
| enable_trpcmdcadapter: true #是否启用trpcmdcadapter |
60 changes: 60 additions & 0 deletions
60
...ation-test/java/com/tencent/trpc/integration/test/transport/slf4j/TrpcMDCAdapterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Tencent is pleased to support the open source community by making tRPC available. | ||
| * | ||
| * Copyright (C) 2023 THL A29 Limited, a Tencent company. | ||
| * All rights reserved. | ||
| * | ||
| * If you have downloaded a copy of the tRPC source code from Tencent, | ||
| * please note that tRPC source code is licensed under the Apache 2.0 License, | ||
| * A copy of the Apache 2.0 License can be found in the LICENSE file. | ||
| */ | ||
|
|
||
| package com.tencent.trpc.integration.test.transport.slf4j; | ||
|
|
||
| import com.tencent.trpc.core.rpc.RpcClientContext; | ||
| import com.tencent.trpc.integration.test.TrpcServerApplication; | ||
| import com.tencent.trpc.integration.test.stub.EchoAPI; | ||
| import com.tencent.trpc.integration.test.stub.EchoService; | ||
| import com.tencent.trpc.spring.annotation.TRpcClient; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.slf4j.TrpcMDCAdapter; | ||
| import org.slf4j.spi.MDCAdapter; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.test.context.junit4.SpringRunner; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| @RunWith(SpringRunner.class) | ||
| @SpringBootTest(classes = TrpcServerApplication.class) | ||
| @ActiveProfiles("transport") | ||
| public class TrpcMDCAdapterTest { | ||
|
|
||
| @TRpcClient(id = "http-client-7072") | ||
| private EchoAPI http7072EchoAPI; | ||
|
|
||
| @TRpcClient(id = "http-client-7073") | ||
| private EchoAPI http7073EchoAPI; | ||
|
|
||
| /** | ||
| * Test for testTrpcMDCAdapter | ||
| */ | ||
| @Test | ||
| public void testTrpcMDCAdapter() { | ||
|
|
||
| String message = "http-hello"; | ||
| EchoService.EchoResponse response = http7072EchoAPI.echo(new RpcClientContext(), EchoService.EchoRequest.newBuilder() | ||
| .setMessage(message) | ||
| .build()); | ||
| assertEquals(message, response.getMessage()); | ||
| response = http7073EchoAPI.echo(new RpcClientContext(), EchoService.EchoRequest.newBuilder() | ||
| .setMessage(message) | ||
| .build()); | ||
| assertEquals(message, response.getMessage()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个解决方案不太行,这里先关掉了