请注意,这个问题看起来可能是这个问题的重复,但事实并非如此。下面我包括我的理性
我正在尝试将Sleuth / Zipkin跟踪添加到我的项目中。为此,我遵循了本教程。
我的项目已经在使用RabbitMQ在工作正常的不同微服务之间进行通信。
我的问题是,当我使用web连接时,我能够很好地获得跟踪,但当我尝试使用RabbitMQ通信时,我会遇到无法连接错误。
product-composite_1 | 2021-01-28 18:11:46.799 WARN [product-composite,,] 1 --- [ main] o.s.c.s.a.z.ZipkinAutoConfiguration :
Check result of the [RabbitMQSender{addresses=[rabbitmq:5672], queue=zipkin}] contains an error
[CheckResult{ok=false, error=java.lang.RuntimeException: Unable to establish connection to RabbitMQ server}]
正如第一行评论的那样,我的问题似乎与rabbitmq主机本身无关,因为它已经启动并运行,并为我的微服务提供服务。
当然,我在配置中遗漏了一些东西,但我找不到它(我也检查了这个帖子,这个和这个。
我的文件(我删除了不相关的部分):
version: '3'
services:
product-composite:
build: microservices/product-composite-service
mem_limit: 350m
environment:
- SPRING_PROFILES_ACTIVE=docker
- CONFIG_SERVER_USR=${CONFIG_SERVER_USR}
- CONFIG_SERVER_PWD=${CONFIG_SERVER_PWD}
depends_on:
- "rabbitmq"
- "eureka"
eureka:
build: spring-cloud/eureka-server
mem_limit: 350m
environment:
- SPRING_PROFILES_ACTIVE=docker
- CONFIG_SERVER_USR=${CONFIG_SERVER_USR}
- CONFIG_SERVER_PWD=${CONFIG_SERVER_PWD}
depends_on:
- "config"
rabbitmq:
image: rabbitmq:3.7.8-management
mem_limit: 350m
ports:
- 5672:5672
- 15672:15672
healthcheck:
test: ["CMD", "rabbitmqctl", "status"]
interval: 10s
timeout: 5s
retries: 10
# https://hub.docker.com/r/openzipkin/zipkin
zipkin:
image: openzipkin/zipkin-slim
mem_limit: 512m
expose:
- "9411"
ports:
- "9411:9411"
environment:
- RABBIT_ADDRESSES=rabbitmq
- STORAGE_TYPE=mem
depends_on:
- "rabbitmq"
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.b-thinking.microservices.composite.product'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/milestone'
}
}
ext {
resilience4jVersion = "1.6.1"
}
dependencies {
// Local projects depedencies
// implementation files('../../api/build/libs/api.1.0.0-SNAPSHOT.jar')
// implementation files('../../util/build/libs/util.1.0.0-SNAPSHOT.jar')
implementation project(':api')
implementation project(':util')
// Testing: Use JSR330 injection
// implementation 'javax.inject:javax.inject:1'
// Implementations dependencies
// Standard (actuator - for monitoring and Health)
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// WebFlux (asynchronous Web)
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// SpringFox dependencies
implementation "io.springfox:springfox-boot-starter:3+"
implementation('io.springfox:springfox-spring-webflux:3+')
// Implementation: Spring cloud
implementation('org.springframework.cloud:spring-cloud-starter-config')
implementation('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
implementation('org.springframework.cloud:spring-cloud-starter-stream-kafka')
// Eureka: Service discovery client
implementation('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
// Security
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.security:spring-security-oauth2-resource-server')
implementation('org.springframework.security:spring-security-oauth2-jose')
// Spring Cloud Configuration through config server
// https://stackoverflow.com/questions/30016868/spring-cloud-config-client-not-loading-configuration-from-config-server
implementation('org.springframework.cloud:spring-cloud-starter-config')
implementation('org.springframework.cloud:spring-cloud-starter-bootstrap')
implementation('org.springframework.retry:spring-retry')
implementation('org.springframework.boot:spring-boot-starter-aop')
// CircuitBreaker with Resilience4J
// From Spring Cloud (abstraction layer): https://spring.io/projects/spring-cloud-circuitbreaker
// implementation('org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j')
// Native from github
implementation("io.github.resilience4j:resilience4j-spring-boot2:${resilience4jVersion}")
implementation("io.github.resilience4j:resilience4j-reactor:${resilience4jVersion}")
// Implementation: Tracing
implementation('org.springframework.cloud:spring-cloud-starter-sleuth')
// implementation('org.springframework.cloud:spring-cloud-starter-zipkin:3.0.0-M4')
implementation "org.springframework.cloud:spring-cloud-sleuth-zipkin"
// Test dependencies
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.projectreactor:reactor-test'
testImplementation('org.springframework.cloud:spring-cloud-stream-test-support')
}
dependencyManagement {
imports {
// mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.0-M5'
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2020.0.0"
}
}
test {
useJUnitPlatform()
}
请注意,它以配置文件“docker”开头,因此Rabbit的主机是Rabbitmq
app:
eureka-username: u
eureka-password: p
eureka-server: localhost
config-server: localhost
zipkin-server: localhost
# Eureka & Ribbon client & instance
eureka:
client:
serviceUrl:
defaultZone: "http://${app.eureka-username}:${app.eureka-password}@${app.eureka-server}:8761/eureka/"
initialInstanceInfoReplicationIntervalSeconds: 5
registryFetchIntervalSeconds: 5
instance:
leaseRenewalIntervalInSeconds: 5
leaseExpirationDurationInSeconds: 5
ribbon:
ServerListRefreshInterval: 5000
NFLoadBalancerPingInterval: 5
spring.cloud.stream:
defaultBinder: rabbit
default.contentType: application/json
rabbit.bindings:
input-products.consumer:
autoBindDlq: true
republishToDlq: true
input-recommendations.consumer:
autoBindDlq: true
republishToDlq: true
input-reviews.consumer:
autoBindDlq: true
republishToDlq: true
bindings:
input-products:
destination: products
group: productsGroup
consumer:
maxAttempts: 3
backOffInitialInterval: 500
backOffMaxInterval: 1000
backOffMultiplier: 2.0
input-recommendations:
destination: recommendations
group: recommendationsGroup
consumer:
maxAttempts: 3
backOffInitialInterval: 500
backOffMaxInterval: 1000
backOffMultiplier: 2.0
input-reviews:
destination: reviews
group: reviewsGroup
consumer:
maxAttempts: 3
backOffInitialInterval: 500
backOffMaxInterval: 1000
backOffMultiplier: 2.0
output-products:
destination: products
producer:
required-groups: auditGroup
output-recommendations:
destination: recommendations
producer:
required-groups: auditGroup
output-reviews:
destination: reviews
producer:
required-groups: auditGroup
sleuth-stream-save:
destination: sleuth-stream-save
group: sleuth-stream
content-type: application/json
#endregion: Microservices streams
spring.rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest
# Tracing
spring.zipkin.enabled: true
# spring.zipkin.sender.type: web
spring.zipkin.sender.type: rabbit
spring.zipkin.base-url: http://localhost:9411
spring.zipkin.rabbitmq.addresses: localhost:5672
# // Trace all (normally is only 10% with 0.1)
spring.sleuth.sampler.probability: 1.0
# spring.sleuth.sampler.percentage: 1.0
# WARNING: Exposing all management endpoints over http should only be used during development, must be locked down in production!
logging:
level:
root: DEBUG
---
spring.config.activate.on-profile: docker
app:
eureka-server: eureka
config-server: config
zipkin-server: zipkin
spring.rabbitmq.host: rabbitmq
spring.zipkin.base-url: http://zipkin:9411
spring.zipkin.rabbitmq.addresses: rabbitmq:5672
我无法用spring cloud sleuth示例zipkin应用程序复制您的问题(它对我有效),以下是我所做的:
org.springframework.amqp:Spring兔
到pom.xml
spring.zipkin.sender.type:兔子
到application.yml
zipkin
)解决这一问题的几点建议:
Created new connection: rabbitConnectionFactory#21917b6f:0/SimpleConnection@40803682 [delegate=amqp://guest@127.0.0.1:5672/, localPort= 60265]
尝试使用示例使其工作,并尝试使工作示例更接近您的应用程序(通过添加依赖项),看看两者之间有什么区别,以及它将在哪里崩溃。如果你能创建一个重现问题的最小样本应用程序(例如:基于zipkin样本),请随意在GH:https://github.com/spring-cloud/spring-cloud-sleuth上创建一个问题并标记我(< code>@jonatan-ivanov),我可以看看。
我终于找到了。我有两个问题
1 -我使用zipkin-slim docker图像作为我的zip容器。此映像不包含rabbitmq收集器rabbitmq收集器。我用standar zipkin的图像代替
2 - 我不知道为什么,但是从侦探/zipkin到RabbitMQ的连接没有重试(我将进一步调查)。因此,如果我赶时间并且很早就进行了测试(当RabbitMQ尚不可用时),它将失败,并且不会重试。
我的docker-comuse相关部分现在是这样的:
rabbitmq:
image: rabbitmq:3.7.8-management
mem_limit: 350m
expose:
- "5672"
- "15672"
ports:
- 5672:5672
- 15672:15672
healthcheck:
test: ["CMD", "rabbitmqctl", "status"]
interval: 10s
timeout: 5s
retries: 10
# https://hub.docker.com/r/openzipkin/zipkin
zipkin:
#image: openzipkin/zipkin-slim
image: openzipkin/zipkin
mem_limit: 512m
expose:
- "9411"
ports:
- "9411:9411"
environment:
- RABBIT_ADDRESSES=rabbitmq
- STORAGE_TYPE=mem
depends_on:
rabbitmq:
condition: service_healthy
再次感谢乔纳坦·伊万诺夫帮助我!
使用依赖关系spring-cloud-starter-zipkin,应用程序应该在sleuth触发时连接到zipkin服务器。我没有启动zipkin服务器,所以它应该抛出一个连接异常。但什么也没发生。而当我启动zipkin服务器时,它不能接收任何东西。 应用程序.属性 和日志
我正在尝试使用Kubernetes 1.7.12 fluentd elasticsearch插件:https://github.com/kubernetes/kubernetes/tree/v1.7.12/cluster/addons/fluentd-elasticsearch ElasticSearch启动并可以响应: 但Kibana仍然无法连接到它。连接错误始于: ElasticSearch启
麋鹿堆叠码头工人的新手。 正在尝试在docker中本地设置麋鹿设置。 使用的命令是 ElasticSeach是向上和http://localhost:9200/是给json响应。 但是kibana url(http://localhost:5601/)说“Kibana服务器还没有准备好”,请求在浏览器中继续旋转。 在查询docker容器时,它说, 编辑调查结果:- 1.最初是命令 立即给出空洞的回
我在Windows10机器上尝试将RabbitMQ(3.6.11版本与Erlang 20一起安装)连接到ZipKin,但我得到了以下错误: 原因:org.springframework.beans.factory.unsatisfieddependencyException:创建名为“server configurator”的bean时出错,该bean在zipkin2.server.interna
使用来自DBCP的BasicDataSource,如果我们执行getConnection()并且在最后一个块中我们关闭连接,它是真的将连接返回到池还是关闭连接。我正在检查的代码片段是这样的 我正在检查BasicDataSource的源代码,并访问了这个包装类以获取连接。 委托对象的类型为java。sql。联系包装器代码调用委托的close方法,该方法将关闭集合,而不是将连接返回到池。这是DBCP的
我有zipkin服务器作为Spring Boot应用程序运行。我已经将jar导出到docker容器。 我已经探索过这个环节。