我有一些spring服务可以提交一些AWS批处理作业。这是调用外部服务请求的简单spring批处理作业。并且我想通过将“org.springframework.cloud:spring-cloud-starter-sleuth”lib包含到classpath中,将在我的服务中生成的traceId传播到这个作业中,并将“traceRestTemplateInterceptor”拦截器添加到用这个traceId初始化的外部请求中。
我怎么能那样做?我如何初始化拦截器,它将把现有的traceId从应用程序参数,环境,属性?或者可能需要创建一些配置bean?
@SpringBootApplication
public class DemoApplication implements CommandLineRunner {
Logger logger = LoggerFactory.getLogger(DemoApplication.class);
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
//@Autowired
//RestTemplate restTemplate;
@Override
public void run(String... args) {
logger.info("Hello, world!");
//restTemplate.getForObject("some_url", String.class);
}
}
x-b3-traceId=98519d97ce87553d
dependencies {
implementation('org.springframework.cloud:spring-cloud-starter-sleuth')
}
INFO [-,,,] 15048 --- [ main] com.example.demo.DemoApplication : Hello, world!
仅通过手动将具有相应值的请求头键“x-b3-traceid”(外部应用程序在提交目标Spring Boot应用程序时作为系统属性插入)解决了此问题。并在MDC中手动插入此键。例如,这个来自Spring Boot应用程序的代码片段必须获取traceId并传播:
@Bean
public void setTraceIdToMDC(@Value("${x.b3.traceid}") String traceId) {
MDC.put("x-b3-traceId", traceId);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean
public CommandLineRunner commandLineRunnerer(RestTemplate restTemplate, @Value("${x.b3.traceid}") String traceId) {
return args -> {
MultiValueMap<String, String> header = new LinkedMultiValueMap<>();
header.add("X-B3-TRACEID", traceId);
HttpEntity httpEntity = new HttpEntity(header);
logger.info("Execute some request"); //<-- prints expected traceId
restTemplate.exchange("some_url", HttpMethod.GET, httpEntity, String.class);
};
}
我正在尝试设置多线程应用程序的跟踪。我已设置线程池: 所以有几个线程。其中一个线程正在侦听SQS队列: 在此代码段中
我使用下载管理器将文件下载到外部存储器。我使用设置下载文件夹的目标 成功后,我用 这给了我这个 现在我试着用intent播放这个视频文件 这里的内容Uri是 但当我使用action\u share intent时,它也不会被其他应用程序识别。 此外,必须删除包含file://的文件uri,并将其替换为/storage/emulated/0/Download/dishapatani\u Jan 07
我目前正在我们的项目中实现Spring Cloud Sleuth。我需要将traceId添加到响应标头。有没有办法实现这一点? 谢谢, Anoop
问题内容: 我想将路由分为不同的文件,其中一个文件包含所有路由,另一个文件包含相应的操作。我目前有一个解决方案来实现此目的,但是我需要使应用程序实例成为全局实例,以便能够在操作中对其进行访问。我当前的设置如下所示: app.js: route.js: 控制器/index.js: 控制器/posts.js: 但是,此设置存在一个大问题:我需要传递给操作(controllers / *。js)的数据库
在WebFlux应用程序中复制这种行为的正确方法是什么?
我试图通过将提供程序的设置为来破坏安全性,但是会在内部检查自己是否导出,如果导出了,它会抛出一个异常。