使用用户名和密码时 RabbitMQ C# 连接问题

RabbitMQ C# connection trouble when using a username and password(使用用户名和密码时 RabbitMQ C# 连接问题)
本文介绍了使用用户名和密码时 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# 连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)