RabbitMQ C# connection trouble when using a username and password(使用用户名和密码时 RabbitMQ C# 连接问题)
问题描述
我在这里不知所措,所以我正在寻求集体知识,希望能出现奇迹.
I am at a loss here so I'm reaching out to the collective knowledge in hope of a miracle.
我已经使用默认设置在 Linux 机器上安装了 RabbitMQ.
I have installed RabbitMQ on a Linux box using the defaults.
当我使用此代码(以及默认的 RabbitMQ 安装配置)时,一切正常.
When I use this code (and the default RabbitMQ installation configuration) everything works nice.
var connectionFactory = new ConnectionFactory();
connectionFactory.HostName = "192.168.0.12";
IConnection connection = connectionFactory.CreateConnection();
但是当我将用户添加到 RabbitMQ 并尝试使用以下代码时(用户名和密码已更改以保护无辜.:))
But when I add a user to RabbitMQ and try to use the following code (username and password has been changed to protect the innocent. :) )
var connectionFactory = new ConnectionFactory();
connectionFactory.HostName = "192.168.0.12";
connectionFactory.UserName = "user";
connectionFactory.Password = "password";
IConnection connection = connectionFactory.CreateConnection();
connectionFactory.CreateConnection()
方法抛出以下异常:
BrokerUnreachableException
None of the specified endpoints were reachable
检查 RabbitMQ 日志文件,我可以看到它抱怨凭据:
Checking the RabbitMQ logfile I can see it complaining about the credentials:
{amqp_error,access_refused,
"PLAIN login refused: user 'user' - invalid credentials",
'connection.start_ok'}}
问题是我对用户名和密码很有信心,但由于热爱编码,我无法在任何地方找到解决方案.
The thing is that I am confident about the username and password and I cannot for the love of coding find a solution to this anywhere.
我一定遗漏了一些明显的东西,但我不知道它是什么.如果有任何有用的指点,我将不胜感激.
I must be missing something obvious but I can't figure out what it is. I would be grateful for any helpful pointers.
推荐答案
看来我找到了解决自己问题的方法.以下代码有效:
It seems that I have found a solution to my own problem. The following code works:
ConnectionFactory factory = new ConnectionFactory();
factory.UserName = "user";
factory.Password = "password";
factory.VirtualHost = "/";
factory.Protocol = Protocols.FromEnvironment();
factory.HostName = "192.168.0.12";
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
IConnection conn = factory.CreateConnection();
感谢您的聆听,也许这至少对其他人有用.:)
Thanks for listening and perhaps this at least could be useful to someone else. :)
这篇关于使用用户名和密码时 RabbitMQ C# 连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用用户名和密码时 RabbitMQ C# 连接问题


- 带问号的 nvarchar 列结果 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 使用 rss + c# 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01