spring cloud sleuth zipkin http收集
*********************************
Start zipkin-server
docker run -it -d --net fixed3 --ip 192.168.57.2 -e "QUERY_PORT=8080" --name zipkin openzipkin/zipkin
Description: use http collection, memory storage, custom port 8080
*********************************
Service 1: hello-service
*********************
Configuration file
spring:
application:
name: hello-service
cloud:
consul:
host: 192.168.57.21
port: 8500
zipkin:
base-url: http://192.168.57.2:8080
*********************
controller layer
HelloController
@RestController
public class HelloController {
private Logger logger= LoggerFactory.getLogger(HelloController.class);
@RequestMapping("/hello")
public String hello(){
logger.info("hello controller:{}","hello world");
return "hello world";
}
}
*********************************
Service 2: hello-consumer
*********************
Configuration file
spring:
application:
name: hello-consumer
cloud:
consul:
host: 192.168.57.21
port: 8500
zipkin:
base-url: http://192.168.57.2:8080
*********************
service layer
HelloService
@FeignClient(name = "hello-service",fallback = HelloServiceImpl.class)
public interface HelloService {
@RequestMapping("/hello")
String hello();
}
*********************
serviceImpl layer
HelloServiceImpl
@Service
public class HelloServiceImpl implements HelloService {
@Override
public String hello() {
return "本地输出:"+"hello world";
}
}
*********************
controller layer
HelloConsumerController
@RestController
public class HelloConsumerController {
private Logger logger= LoggerFactory.getLogger(HelloConsumerController.class);
@Resource
private HelloService helloService;
@RequestMapping("/consume")
public String consume(){
logger.info("调用 hello-service:{}",helloService.hello());
logger.info("本地输出:{}","hello consumer controller");
return "hello consumer";
}
}
***************************
Use test
Call / consume interface
Call the / consume interface again
Description: Call the interface again, two log records appear