导读:文章目录 Spring Cloud sleuth with zipkin over RabbitMQ demo zipkin server的搭建(基于mysql和rabbitMQ) 客户端环境的依赖 如何调用 Spring Cloud sleuth with zipkin over RabbitMQ demo 本项目是sleuth和zipkin在spring cloud环境中使用,其中sleuth
文章目录
Spring Cloud sleuth with zipkin over RabbitMQ demo
zipkin server的搭建(基于mysql和rabbitMQ)
客户端环境的依赖
如何调用
Spring Cloud sleuth with zipkin over RabbitMQ demo
---- Copyright 2015-2019 The OpenZipkin Authors---- Licensed under the Apache License,Version 2.0 (the "License"); you may not use this file except-- in compliance with the License. You may obtain a copy of the License at---- http://www.apache.org/licenses/LICENSE-2.0---- Unless required by applicable law or agreed to in writing,software distributed under the License-- is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express-- or implied. See the License for the specific language governing permissions and limitations under-- the License.--CREATETABLEIFNOTEXISTS zipkin_spans (`trace_id_high`BIGINTNOTNULLDEFAULT0COMMENT'If non zero,this means the trace uses 128 bit traceIds instead of 64 bit',`trace_id`BIGINTNOTNULL,`id`BIGINTNOTNULL,`name`VARCHAR(255)NOTNULL,`remote_service_name`VARCHAR(255),`parent_id`BIGINT,`debug`BIT(1),`start_ts`BIGINTCOMMENT'Span.timestamp(): epoch micros used for endTs query and to implement TTL',`duration`BIGINTCOMMENT'Span.duration(): micros used for minDuration and maxDuration query',PRIMARYKEY(`trace_id_high`,`trace_id`,`id`))ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTERSET=utf8 COLLATE utf8_general_ci;ALTERTABLE zipkin_spans ADDINDEX(`trace_id_high`,`trace_id`)COMMENT'for getTracesByIds';ALTERTABLE zipkin_spans ADDINDEX(`name`)COMMENT'for getTraces and getSpanNames';ALTERTABLE zipkin_spans ADDINDEX(`remote_service_name`)COMMENT'for getTraces and getRemoteServiceNames';ALTERTABLE zipkin_spans ADDINDEX(`start_ts`)COMMENT'for getTraces ordering and range';CREATETABLEIFNOTEXISTS zipkin_annotations (`trace_id_high`BIGINTNOTNULLDEFAULT0COMMENT'If non zero,`trace_id`BIGINTNOTNULLCOMMENT'coincides with zipkin_spans.trace_id',`span_id`BIGINTNOTNULLCOMMENT'coincides with zipkin_spans.id',`a_key`VARCHAR(255)NOTNULLCOMMENT'BinaryAnnotation.key or Annotation.value if type == -1',`a_value`BLOBCOMMENT'BinaryAnnotation.value(),which must be smaller than 64KB',`a_type`INTNOTNULLCOMMENT'BinaryAnnotation.type() or -1 if Annotation',`a_timestamp`BIGINTCOMMENT'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',`endpoint_ipv4`INTCOMMENT'Null when Binary/Annotation.endpoint is null',`endpoint_ipv6`BINARY(16)COMMENT'Null when Binary/Annotation.endpoint is null,or no IPv6 address',`endpoint_port`SMALLINTCOMMENT'Null when Binary/Annotation.endpoint is null',`endpoint_service_name`VARCHAR(255)COMMENT'Null when Binary/Annotation.endpoint is null')ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTERSET=utf8 COLLATE utf8_general_ci;ALTERTABLE zipkin_annotations ADDUNIQUEKEY(`trace_id_high`,`span_id`,`a_key`,`a_timestamp`)COMMENT'Ignore insert on duplicate';ALTERTABLE zipkin_annotations ADDINDEX(`trace_id_high`,`span_id`)COMMENT'for joining with zipkin_spans';ALTERTABLE zipkin_annotations ADDINDEX(`trace_id_high`,`trace_id`)COMMENT'for getTraces/ByIds';ALTERTABLE zipkin_annotations ADDINDEX(`endpoint_service_name`)COMMENT'for getTraces and getServiceNames';ALTERTABLE zipkin_annotations ADDINDEX(`a_type`)COMMENT'for getTraces and autocomplete values';ALTERTABLE zipkin_annotations ADDINDEX(`a_key`)COMMENT'for getTraces and autocomplete values';ALTERTABLE zipkin_annotations ADDINDEX(`trace_id`,`a_key`)COMMENT'for dependencies job';CREATETABLEIFNOTEXISTS zipkin_dependencies (`day`DATENOTNULL,`parent`VARCHAR(255)NOTNULL,`child`VARCHAR(255)NOTNULL,`call_count`BIGINT,`error_count`BIGINT,PRIMARYKEY(`day`,`parent`,`child`))ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTERSET=utf8 COLLATE utf8_general_ci;
@RestController@RequestMapping("/serviceTwo")publicclassServiceTwoController{@GetMapping("callServiceTwo")public String callServiceOne(){
log.info("service two is called!");return"service two is called!";}}
我们在service1中用restTemplet来调用它:
@RestController@RequestMapping("/serviceOne")publicclassServiceOneController{@GetMapping("callServiceOne")public String callServiceOne(){
log.info("service one is called!");restTemplate().getForObject("http://localhost:9000/serviceTwo/callServiceTwo",String.class);return"service one and two are called!";}@Bean
RestTemplate restTemplate(){returnnewRestTemplate();}}
这样,我们用get 去请求http://loalhost/serviceOne/callServiceOne 就会将调用信息发送到MQ,并被zipkin Server 处理。 我们就可以在zipkin web页面看到调用信息啦 。