【发布时间】:2018-04-04 21:03:47
【问题描述】:
我正在创建一个客户端应用程序,其想法是将新消息发布到远程 RabbitMQ 队列。我正在使用 MassTransit 创建此客户端,我的代码如下所示:
static IBusControl CreateBus()
{
return Bus.Factory.CreateUsingRabbitMq(x =>
{
var host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h =>
{
h.Username("user");
h.Password("password");
});
});
}
static IRequestClient<ISyncProject, IProjectSynced> CreateRequestClient(IBusControl busControl)
{
var serviceAddress = new Uri(ConfigurationManager.AppSettings["ServiceAddress"]);
IRequestClient<ISyncProject, IProjectSynced> client =
busControl.CreateRequestClient<ISyncProject, IProjectSynced>(serviceAddress, TimeSpan.FromDays(1));
return client;
}
private static async Task MainLogic(IBusControl busControl)
{
IRequestClient<ISyncProject, IProjectSynced> client = CreateRequestClient(busControl);
//I'm using the client here as I show below, this part is not important it works with localhost
IProjectSynced response = await client.Request(new ProjecToSync() { OriginalOOMID = OriginalOOMID });
}
配置文件如下所示:
<appSettings>
<add key="RabbitMQHost" value="rabbitmq://ServerName" />
<add key="ServiceQueueName" value="queueName" />
<add key="ServiceAddress" value="rabbitmq://ServerName/queueName" />
</appSettings>
我没有使用访客用户,我创建了一个新用户并添加了所有管理员权限。
现在,如果我在运行 RabbitMQ 的同一台服务器上运行客户端应用程序并将ServerName 更改为localhost,则此代码有效。如果我使用服务器的任何 ServerName 或 IP 地址在本地计算机上运行客户端,RabbitMQ 将阻止我的连接:
我认为这必须与我需要在服务器中进行的一些配置有关,但到目前为止我还没有找到它。
【问题讨论】:
-
您缺少一些急需的细节。你遇到了什么错误?这台机器是在同一个子网上还是在不同的子网上?是否有防火墙或其他直通设备可能会妨碍您?
-
是同一个子网
-
好的,我刚看到最后一张图片。因此,如果说“阻塞”的那个问题是问题所在,那么这篇文章中的所有其他内容都是无关紧要的。有一个描述条件的page - 你看过了吗?
-
是的,我看到了,但是如果连接被阻止,那是要通知的,对吧?大概是服务器的防火墙
-
不,阻塞是服务器在您遇到资源问题时所做的事情。你没有提供任何关于服务器发生了什么的细节,所以我什至无法推测。也许是内存或磁盘空间?
标签: c# rabbitmq remote-access masstransit