2017-07-05 101 views
1

我的搬運工,撰寫文件看起來像這樣:RabbitMQ的拒絕連接

version: '2' 

services: 
    explore: 
    image: explore 
    build: 
     context: ./Explore 
     dockerfile: VsDockerfile 
    environment: 
     - "ElasticUrl=http://localhost:9200" 
     - "RabbitMq/Host=localhost" 
     - "RabbitMq/Username=guest" 
     - "RabbitMq/Password=guest" 
    networks: 
     - localnet 

    elasticsearch: 
    image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3 
    container_name: elasticsearch 
    environment: 
     - "ES_JAVA_OPTS=-Xms512m -Xmx512m" 
    ports: 
     - 9200:9200 
    volumes: 
     - ./esdata:/usr/share/elasticsearch/data 
    networks: 
     - localnet 

    rabbit: 
    image: rabbitmq:3.6.7-management 
    hostname: rabbit 
    ports: 
     - 15672:15672 
     - 5672:5672 
    networks: 
     - localnet 

networks: 
    localnet: 
    external: 
     name: localnet 

如果我在瀏覽器中鍵入http://localhost:15672,我得到的RabbitMQ接口,但如果我試圖從我的探索項目連接像這樣:

public SqlToRabbitProcessor(SqlToRabbitRepository sqlToRabbitRepository) 
{ 
    _sqlToRabbitRepository = sqlToRabbitRepository; 

    var factory = new ConnectionFactory 
    { 
     HostName = Environment.GetEnvironmentVariable("RabbitMq/Host"), 
     UserName = Environment.GetEnvironmentVariable("RabbitMq/Username"), 
     Password = Environment.GetEnvironmentVariable("RabbitMq/Password") 
    }; 

    var rabbit = factory.CreateConnection(); 
    channel = rabbit.CreateModel(); 
} 

然後在該行

var rabbit = factory.CreateConnection(); 

與錯誤打破說法

ExtendedSocketException:連接被拒絕127.0.0.1:5672 System.Net.Sockets.Socket.EndConnect(IAsyncResult的asyncResult)

ConnectFailureException:連接失敗 RabbitMQ.Client.EndpointResolverExtensions.SelectOne(IEndpointResolver解析器,Func鍵選擇)

BrokerUnreachableException:所述指定的端點沒有一個是可到達的 RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver,串clientProvidedName)

+0

嗯我認爲問題是在我的web容器我打電話localhost,這不是主機本地主機,但容器 – Joshlo

回答

1

由於這個問題在我的評論所說,這是因爲「localhost」的Web應用程序中的部分定義的是它的容器本地主機,而不是搬運工主機..

只是需要改變

- "ElasticUrl=http://localhost:9200" 
- "RabbitMq/Host=localhost" 

- "ElasticUrl=http://elasticsearch:9200" 
- "RabbitMq/Host=rabbit"