我正在使用MassTransit和RabbitMQ建立一个项目。我从docker-compose.yml
文件中启动RabbitMQ和图像,但是图像连接后立即断开连接,而没有非常有用的错误消息
我已经进行了一些谷歌搜索,但到目前为止没有成功。如果有人可以给我任何指示,将不胜感激!
公交初始化:
IBusControl CreateBus(IServiceProvider serviceProvider)
{
return Bus.Factory.CreateUsingRabbitMq(cfg => {
cfg.Host("rabbitmq", h => {
h.Username("guest");
h.Password("guest");
});
});
}
services.AddMassTransit(CreateBus);
docker-compose.yml:
version: "2"
services:
rabbit:
hostname: rabbit
image: rabbitmq:3-management
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
ports:
- 5672:5672
- 15672:15672
my-cool-api:
build:
context: .
dockerfile: ./Dockerfile
image: my-cool-api
container_name: my-cool-api
hostname: my-cool-api
ports:
- 1070:80
environment:
- RabbitMq:Hostname=rabbit
depends_on:
- rabbit
错误堆栈跟踪:
rabbit_1 | 2020-01-20 16:22:02.040 [info] <0.570.0> accepting AMQP connection <0.570.0> (172.22.0.3:34100 -> 172.22.0.2:5672)
rabbit_1 | 2020-01-20 16:22:02.053 [info] <0.570.0> Connection <0.570.0> (172.22.0.3:34100 -> 172.22.0.2:5672) has a client-provided name: dotnet
rabbit_1 | 2020-01-20 16:22:02.056 [info] <0.570.0> connection <0.570.0> (172.22.0.3:34100 -> 172.22.0.2:5672 - dotnet): user 'guest' authenticated and granted access to vhost '/'
rabbit_1 | 2020-01-20 16:22:02.081 [info] <0.570.0> closing AMQP connection <0.570.0> (172.22.0.3:34100 -> 172.22.0.2:5672 - dotnet, vhost: '/', user: 'guest')
my-cool-api | Unhandled exception. System.AggregateException: One or more errors occurred. (One or more errors occurred. (Broker unreachable: guest@rabbit:5672/))
my-cool-api | ---> System.AggregateException: One or more errors occurred. (Broker unreachable: guest@rabbit:5672/)
my-cool-api | ---> MassTransit.RabbitMqTransport.RabbitMqConnectionException: Broker unreachable: guest@rabbit:5672/
my-cool-api | ---> RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable
my-cool-api | ---> System.AggregateException: One or more errors occurred. (Connection failed)
my-cool-api | ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed
my-cool-api | ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (111): Connection refused 172.22.0.2:5672
my-cool-api | at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
my-cool-api | at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
my-cool-api | at System.Net.Sockets.Socket.<>c.<ConnectAsync>b__275_0(IAsyncResult iar)
my-cool-api | --- End of stack trace from previous location where exception was thrown ---
my-cool-api | at RabbitMQ.Client.TcpClientAdapter.ConnectAsync(String host, Int32 port)
my-cool-api | at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, Int32 millisecondsTimeout)
my-cool-api | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, Int32 timeout)
my-cool-api | --- End of inner exception stack trace ---
my-cool-api | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 timeout, AddressFamily family)
my-cool-api | at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingIPv4(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 timeout)
my-cool-api | at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 connectionTimeout, Int32 readTimeout, Int32 writeTimeout)
my-cool-api | at RabbitMQ.Client.Framing.Impl.IProtocolExtensions.CreateFrameHandler(IProtocol protocol, AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 connectionTimeout, Int32 readTimeout, Int32 writeTimeout)
...