Spring Cloud 学习系列:(十五)微服务跟踪链——Spring Cloud Sleuth

本文介绍了如何在Spring Cloud项目中集成Spring Cloud Sleuth和Zipkin,以实现微服务的跟踪链。首先,通过在pom.xml引入起步依赖spring-cloud-starter-zipkin,并在配置文件中设置spring.zipkin.base-url。然后,展示了如何在微服务中对外暴露接口并使用RestTemplate进行通信。此外,还提到了相同步骤应用于其他微服务。最后,提到了Spring Boot、Spring Cloud Alibaba和Spring MVC的相关学习资源。
摘要由CSDN通过智能技术生成

(1)、在其pom引入起步依赖spring-cloud-starter-zipkin,代码如下:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd”>

4.0.0

com.riemann

microservice-sleuth-zipkin

0.0.1-SNAPSHOT

com.riemann

microservice-service-zipkin-hi

0.0.1-SNAPSHOT

microservice-service-zipkin-hi

service-zipkin-hi

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-zipkin

(2)、在其配置文件application.properties指定zipkin server的地址,通过配置spring.zipkin.base-url指定:

通过引入spring-cloud-starter-zipkin依赖和设置spring.zipkin.base-url就可以了。

(3)、对外暴露接口:

package com.riemann.microserviceproviderservicehi;

import java.util.logging.Level;

import java.util.logging.Logger;

import brave.sampler.Sampler;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.context.annotation.Bean;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.client.RestTemplate;

@SpringBootApplication

@RestController

public class MicroserviceProviderServiceHiApplication {

public static void main(String[] args) {

SpringApplication.run(MicroserviceProviderServiceHiApplication.class, args);

}

private static final Logger l

  • 30
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值