我的搬運工,撰寫文件看起來像這樣: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)
嗯我認爲問題是在我的web容器我打電話localhost,這不是主機本地主機,但容器 – Joshlo