一个微服务如何与另一个微服务中的Elasticsearch实例通信?

时间:2019-04-05 12:31:26

标签: docker elasticsearch docker-compose microservices

我目前有2个微服务正在运行。其中之一已启动Elasticsearch并作为容器运行,并且数据已推送至Elasticsearch。另一个微服务需要命中一个在elasticsearch中隐藏数据的端点,并在浏览器中显示该数据。可以在kibana中看到数据,但在其他微服务到达该端点时看不到数据。我可能做错了什么?

我尝试在其他微服务.env文件中添加elasticsearch别名的名称,但似乎仍无法与elasticsearch通信。

------microservice 1-----
version: '3.5'
services:
  micro1_php:
    environment:
      SERVICE_NAME: micro1-app
      DB_CONNECTION: local
      ELASTIC_HOST: mic_elasticsearch
      ELASTIC_PORT: 9200
    networks:
      - default
      - proxynet

  mic_elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3
    environment:
      discovery.type: single-node
    volumes:
      - "./storage/es-data:/usr/share/elasticsearch/data"  # to be persistant across docker-compose restarts
    networks:
      default: {}
      proxynet:
        aliases:
          - micro.elasticsearch
    ports:
      - "9200:9200"

networks:
  proxynet:
    name: custom_network
    external: true







------microservice 2-----
version: '3.5'
services:
  micro2_php:
    environment:
      SERVICE_NAME: micro2-app
      DB_CONNECTION: local
    networks:
      - default
      - proxynet


networks:
  proxynet:
    name: custom_network
    external: true

0 个答案:

没有答案