首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zipkin没有连接到RabbitMQ

Zipkin没有连接到RabbitMQ
EN

Stack Overflow用户
提问于 2021-01-28 18:48:26
回答 2查看 1.8K关注 0票数 1

请注意,注意到这个问题可能看起来是这一个的重复,但事实并非如此。下面我包括我的理性

我正试图在我的项目中添加侦察/Zipkin追踪。为此,我跟踪了这个教程

我的项目已经在使用RabbitMQ在不同的微服务之间进行通信。

我的问题是,当我使用web连接时,我能够很好地获得跟踪,但是当我尝试使用RabbitMQ进行通信时,我会出现一个无法连接的错误。

代码语言:javascript
复制
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主机本身无关,因为它已经启动和运行,并为我的微服务提供服务。

当然,我在配置中遗漏了一些东西,但我找不到它(我还检查了这个职位

我的档案(我已经删除了无关的部分):

docker-compose.yml

代码语言:javascript
复制
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"

build.gradle

代码语言:javascript
复制
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()
}

application.yml

注意,它是从profile 'docker‘开始的,所以兔子的宿主是rabbitmq。

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2021-01-30 09:30:34

自应答

终于找到了。我有两个问题

我用zipkin-纤细的码头形象作为我的拉链容器。此映像不包含rabbitmq收集器狂犬病收集器。我已经用标准的zipkin图像代替了

我不知道为什么,但是从侦探/zipkin到RabbitMQ的联系没有重新尝试(我会进一步调查)。因此,如果我非常匆忙地进行测试(当RabbitMQ还没有可用时),它就会失败,而不会重试。

我的对接者-撰写相关章节现在如下:

代码语言:javascript
复制
  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

再次感谢约拿坦·伊万诺夫帮助我!

票数 3
EN

Stack Overflow用户

发布于 2021-01-29 22:17:20

我无法重现弹簧云-雪橇-样本-zipkin应用程序的问题(它对我有用),下面是我所做的:

  1. org.springframework.amqp:spring-rabbit添加到pom.xml
  2. spring.zipkin.sender.type: rabbit添加到application.yml
  3. 使用RabbitMQ启动这个船坞-复合的。
  4. 在兔子管理UI上手动创建一个队列(名为zipkin)
  5. 启动应用程序,并按下请求。
  6. 手动将消息从队列中取出,并检查它们是否具有正确的有效负载(确实如此)

解决此问题的几个提示:

  1. 您应该在启动时看到这个日志事件。
代码语言:javascript
复制
Created new connection: rabbitConnectionFactory#21917b6f:0/SimpleConnection@40803682 [delegate=amqp://guest@127.0.0.1:5672/, localPort= 60265]
  1. 连接是由AbstractConnectionFactory创建的,您可以调试它。
  2. Telnet (telnet localhost 5672)可以帮助解决连接问题。

尝试使用示例使其工作,并尝试使工作示例更接近您的应用程序(通过添加依赖项),并查看两者之间的区别以及它将在哪里崩溃。如果您可以创建一个复制问题的最小示例应用程序(例如:基于zipkin示例),请在GH:https://github.com/spring-cloud/spring-cloud-sleuth上创建一个问题并标记我(@jonatan-ivanov),我可以查看。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65943408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档