RabbitMQ C# 演示无法使用远程主机工作

问题描述 投票:0回答:0

RabbitMQ C# 演示无法使用远程主机工作

当尝试创建频道时,我得到:

Unhandled exception. RabbitMQ.Client.Exceptions.OperationInterruptedException: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=541, text='Unexpected Exception', classId=0, methodId=0, cause=System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..

我的客户端是Windows 10,donet 7.0,包“RabbitMQ.Client”版本=“6.5.0” 服务器运行在 Ubuntu 22.04,RabbitMQ 版本:3.9.13

这是代码:

using System.Text;
using RabbitMQ.Client;

ConnectionFactory factory = new ConnectionFactory();
factory.UserName = "coyote";
factory.Password = "******";
factory.VirtualHost = "/";
//factory.Protocol = Protocols.FromEnvironment();
factory.HostName = "203.0.113.145";
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
IConnection conn = factory.CreateConnection();
Console.WriteLine("create connection");

using var connection = factory.CreateConnection();
Console.WriteLine("connection created");

using var channel = connection.CreateModel();
Console.WriteLine("channel created");

channel.QueueDeclare(queue: "hello",
                     durable: false,
                     exclusive: false,
                     autoDelete: false,
                     arguments: null);
Console.WriteLine("queue declared");

const string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);

channel.BasicPublish(exchange: "greetings",
                     routingKey: "hello",
                     basicProperties: null,
                     body: body);
Console.WriteLine("produced");

Console.WriteLine($" [x] Sent {message}");

Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();

这是输出:

C:\tmp\RabbitMQ\dotnet\send>dotnet run  
create connection
connection created
Unhandled exception. RabbitMQ.Client.Exceptions.OperationInterruptedException: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=541, text='Unexpected Exception', classId=0, methodId=0, cause=System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
 ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.BufferedStream.ReadByteSlow()
   at RabbitMQ.Client.Impl.InboundFrame.ReadFrom(Stream reader, Byte[] frameHeaderBuffer, ArrayPool`1 pool, UInt32 maxMessageSize)
   at RabbitMQ.Client.Impl.SocketFrameHandler.ReadFrame()
   at RabbitMQ.Client.Framing.Impl.Connection.MainLoopIteration()
   at RabbitMQ.Client.Framing.Impl.Connection.MainLoop()
   at RabbitMQ.Client.Impl.SimpleBlockingRpcContinuation.GetReply(TimeSpan timeout)
   at RabbitMQ.Client.Impl.ModelBase.ModelRpc(MethodBase method, ContentHeaderBase header, Byte[] body)
   at RabbitMQ.Client.Framing.Impl.Model._Private_ChannelOpen(String outOfBand)
   at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.CreateNonRecoveringModel()
   at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.CreateModel()
   at Program.<Main>$(String[] args) in C:\tmp\RabbitMQ\dotnet\send\send.cs:line 17

这是服务器上的日志

jpjofre@jpjofre-rmq-01:~$ sudo cat /var/log/rabbitmq/[email protected]
2023-07-27 04:28:52.484326+00:00 [info] <0.695.0> accepting AMQP connection <0.695.0> (203.0.113.1:53056 -> 203.0.113.145:5672)
2023-07-27 04:28:52.495710+00:00 [info] <0.695.0> connection <0.695.0> (203.0.113.1:53056 -> 203.0.113.145:5672): user 'coyote' authenticated and granted access to vhost '/'
2023-07-27 04:28:52.499561+00:00 [info] <0.704.0> accepting AMQP connection <0.704.0> (203.0.113.1:53057 -> 203.0.113.145:5672)
2023-07-27 04:28:52.501529+00:00 [info] <0.704.0> connection <0.704.0> (203.0.113.1:53057 -> 203.0.113.145:5672): user 'coyote' authenticated and granted access to vhost '/'
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>   crasher:
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     initial call: rabbit_reader:init/3
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     pid: <0.704.0>
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     registered_name: []
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     exception exit: {unexpected_message,{'EXIT',#Port<0.70>,einval}}
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>       in function  rabbit_reader:handle_other/2 (rabbit_reader.erl, line 646)
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>       in call from rabbit_reader:mainloop/4 (rabbit_reader.erl, line 537)
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>       in call from rabbit_reader:run/1 (rabbit_reader.erl, line 459)
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>       in call from rabbit_reader:start_connection/4 (rabbit_reader.erl, line 358)
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     ancestors: [<0.702.0>,<0.597.0>,<0.596.0>,<0.595.0>,<0.593.0>,<0.592.0>,
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                   rabbit_sup,<0.235.0>]
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     message_queue_len: 0
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     messages: []
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     links: [<0.702.0>]
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     dictionary: [{client_properties,
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                       [{<<"product">>,longstr,<<"RabbitMQ">>},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                        {<<"version">>,longstr,
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                         <<"6.5.0+4c91cae8ae5eb0194e02a83f1b0cedfe29ad8312">>},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                        {<<"platform">>,longstr,<<".NET">>},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                        {<<"copyright">>,longstr,
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                         <<"Copyright (c) 2007-2020 VMware, Inc.">>},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                        {<<"information">>,longstr,
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                         <<"Licensed under the MPL. See https://www.rabbitmq.com/">>},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                        {<<"capabilities">>,table,
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                         [{<<"publisher_confirms">>,bool,true},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                          {<<"exchange_exchange_bindings">>,bool,true},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                          {<<"basic.nack">>,bool,true},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                          {<<"consumer_cancel_notify">>,bool,true},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                          {<<"connection.blocked">>,bool,true},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                          {<<"authentication_failure_close">>,bool,true}]},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                        {<<"connection_name">>,void,undefined}]},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                   {process_name,
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                       {rabbit_reader,
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                           <<"203.0.113.1:53057 -> 203.0.113.145:5672">>}},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                   {{ch_pid,<0.713.0>},{1,#Ref<0.823110380.820248577.78094>}},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                   {{channel,1},
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>                    {<0.713.0>,{method,rabbit_framing_amqp_0_9_1}}}]
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     trap_exit: true
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     status: running
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     heap_size: 2586
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     stack_size: 28
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>     reductions: 9671
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>   neighbours:
2023-07-27 04:28:52.504761+00:00 [erro] <0.704.0>
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>     supervisor: {<0.702.0>,rabbit_connection_sup}
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>     errorContext: child_terminated
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>     reason: {unexpected_message,{'EXIT',#Port<0.70>,einval}}
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>     offender: [{pid,<0.704.0>},
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>                {id,reader},
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>                {mfargs,{rabbit_reader,start_link,
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>                                       [<0.703.0>,
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>                                        {acceptor,{0,0,0,0,0,0,0,0},5672}]}},
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>                {restart_type,intrinsic},
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>                {shutdown,300000},
2023-07-27 04:28:52.505482+00:00 [erro] <0.702.0>                {child_type,worker}]
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>     supervisor: {<0.702.0>,rabbit_connection_sup}
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>     errorContext: shutdown
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>     reason: reached_max_restart_intensity
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>     offender: [{pid,<0.704.0>},
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>                {id,reader},
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>                {mfargs,{rabbit_reader,start_link,
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>                                       [<0.703.0>,
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>                                        {acceptor,{0,0,0,0,0,0,0,0},5672}]}},
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>                {restart_type,intrinsic},
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>                {shutdown,300000},
2023-07-27 04:28:52.505600+00:00 [erro] <0.702.0>                {child_type,worker}]
2023-07-27 04:28:55.541938+00:00 [warn] <0.695.0> closing AMQP connection <0.695.0> (203.0.113.1:53056 -> 203.0.113.145:5672, vhost: '/', user: 'coyote'):
2023-07-27 04:28:55.541938+00:00 [warn] <0.695.0> client unexpectedly closed TCP connection
c# .net-core rabbitmq
© www.soinside.com 2019 - 2024. All rights reserved.