2

I have 3 projects: A hystrix dashboard, a turbine server (using AMQP) and an API

When I start in development env, I set up 2 instances of the API (using port 8080 and 8081). To test the turbine aggregation, I make calls and in the dashboard, I can see Hosts: 2.
Although when I use Docker, even when the load balancer hits the 2 server, I only see one Host on the hystrix dashboard.

My assumptions:
1- as both containers start on the same port (8080), Turbine sees them as one
2- as I also dockerize RabbitMQ, this may be causing problems

here is my docker-compose.yml file

version: '2'
    services:
      postgres:
        image: postgres:9.5
        ports:
          - "5432"
        environment:
          POSTGRES_PASSWORD: postgres
          POSTGRES_USER: postgres
          POSTGRES_DB: fq
        volumes:
          - /var/lib/postgresql

      rabbitmq:
        image: rabbitmq:3-management
        ports:
          - "5672"
          - "15672"
        environment:
          RABBITMQ_DEFAULT_USER: turbine
          RABBITMQ_DEFAULT_PASS: turbine
        volumes:
          - /var/lib/rabbitmq/

      hystrix:
        build: hystrixdashboard/.
        links:
          - turbine_server
        ports:
          - "8989:8989"

      turbine_server:
        build: turbine/.
        links:
          - rabbitmq
        ports:
          - "8090:8090"

      persona_api:
        build: persona/.
        ports:
          - "8080"
        links:
          - postgres
          - rabbitmq

      lb:
        image: 'dockercloud/haproxy:1.5.1'
        links:
          - persona_api
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
        ports:
          - 80:80

my persona_api config file

 spring:
  application:
    name: persona_api
  profiles:
    active: dev
  rabbitmq:
    addresses: 127.0.0.1:5672
    username: turbine
    password: turbine
    useSSL: false

server:
  compression.enabled: true
  port: ${PORT:8080}

params:
  datasource:
    driverClassName: org.postgresql.Driver
    username: postgres
    password: postgres
    maximumPoolSize: 10
    poolName: fq_connection_pool

spring.jpa:
  show-sql: true
  hibernate:
    ddl-auto: update

turbine:
  aggregator:
    clusterConfig: persona_api
  appConfig: persona_api

---

spring:
  profiles: dev

params:
  datasource:
    jdbcUrl: jdbc:postgresql://127.0.0.1:5432/fq
---

spring:
  profiles: docker
  rabbitmq:
    addresses: rabbitmq:5672

params:
  datasource:
    jdbcUrl: jdbc:postgresql://postgres:5432/fq

I'm afraid that if I deploy it to production (on Rancher or Docker cloud), I'll see the same problem.

here is a GIF of what is happening when I set up two APIs load balanced

enter image description here

4

3 に答える 3

0

問題は、使用しているRabbitMQ接続にあると思います。使用している接続文字列は localhost ですが、実際には、RabbitMQ コンテナーを除いて、接続は localhost で利用できます。環境変数を使用して、Rabbit ホストを Spring 接続に挿入することをお勧めします。あなたのファイルを正しく読めば、それ${RABBITMQ_PORT_5672_TCP_ADDR}は localhost の代わりになるはずです。しかし、私は試すことができなかったことに注意してください。それは単なる経験に基づいた推測です。envすべてが実行されているときに、persona_api コンテナー内で実行して再確認することをお勧めします。

于 2016-06-20T18:50:05.483 に答える