[英]Masstransit - Rabbit MQ virtual host
我正在使用公共交通並連接到我的兔子經紀人。
string uri1 = @"rabbitmq://myusername:mypassword@myip/myvirtualhost/myqueue";
我不斷收到未處理的 ConfigurationException。
服務總線創建過程中拋出異常 {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} {"Failed to start bus services"} at MassTransit.ServiceContainer.Start() in d:\\BuildAgent-03\\work\\aa063b4295dfc097\\src\\MassTransit\\ ServiceContainer.cs:位於 d:\\BuildAgent-03\\work\\aa063b4295dfc097\\src\\MassTransit\\ServiceBus.cs 中 MassTransit.ServiceBus.Start() 的第 83 行:位於 d:\\ BuildAgent-03\\work\\aa063b4295dfc097\\src\\MassTransit\\Configuration\\Builders\\ServiceBusBuilderImpl.cs:line 84 at MassTransit.BusConfigurators.ServiceBusConfiguratorImpl.CreateServiceBus() in d:\\BuildAgent-03\\work\\aa063bsm BusConfigurators\\ServiceBusConfiguratorImpl.cs:line 171 at MassTransit.ServiceBusFactory.New(Action`1 configure) in d:\\BuildAgent-03\\work\\aa063b4295dfc097\\src\\MassTransit\\Configuration\\ServiceBusFactory.cs:line 44
真正奇怪的是,它在沒有指定虛擬主機的情況下工作,但它們偏離了錯誤的虛擬主機。
然后我下載了 rabbitMQ 庫,它使用我的憑據很好地連接到正確的虛擬主機。 這就是我知道我的憑據的方式,虛擬主機設置得很好。 我什至添加了一個隊列以防萬一。 Masstransit 中是否存在一些錯誤? 我真的不明白我做錯了什么。 我正在考慮不使用大眾運輸並編寫我自己的輕量級版本。
我什至將其復制粘貼到https://github.com/MassTransit/MassTransit/blob/v2.7.2/src/Transports/MassTransit.Transports.RabbitMq/RabbitMqEndpointAddress.cs#L167我的解決方案以檢查它是否正在修剪虛擬主機正確,它是。 我真的很困惑。 ` static readonly Regex regex = new Regex(@"^[A-Za-z0-9- .:]+$");
public static RabbitMqEndpointAddress Parse(Uri address)
{
Guard.AgainstNull(address, "address");
if (string.Compare("rabbitmq", address.Scheme, true) != 0)
throw new RabbitMqAddressException("The invalid scheme was specified: " + address.Scheme ?? "(null)");
var connectionFactory = new ConnectionFactory
{
HostName = address.Host,
UserName = "",
Password = "",
};
if (address.IsDefaultPort)
connectionFactory.Port = 5672;
else if (!address.IsDefaultPort)
connectionFactory.Port = address.Port;
if (!address.UserInfo.IsEmpty())
{
if (address.UserInfo.Contains(":"))
{
string[] parts = address.UserInfo.Split(':');
connectionFactory.UserName = parts[0];
connectionFactory.Password = parts[1];
}
else
connectionFactory.UserName = address.UserInfo;
}
string name = address.AbsolutePath.Substring(1);
string[] pathSegments = name.Split('/');
if (pathSegments.Length == 2)
{
connectionFactory.VirtualHost = pathSegments[0];
name = pathSegments[1];
}
ushort heartbeat = address.Query.GetValueFromQueryString("heartbeat", connectionFactory.RequestedHeartbeat);
connectionFactory.RequestedHeartbeat = heartbeat;
VerifyQueueOrExchangeNameIsLegal(name);
return new RabbitMqEndpointAddress(address, connectionFactory, name);
}
static void VerifyQueueOrExchangeNameIsLegal(string path)
{
Match match = _regex.Match(path);
if (!match.Success)
throw new RabbitMqAddressException(FormatErrorMsg);
}
const string FormatErrorMsg =
"The path can be empty, or a sequence of these characters: letters, digits, hyphen, underscore, period, or colon.";
private static void Main(string[] args)
{
string uri1 = @"rabbitmq://username:password@mydomain.co.za/vhost/queue";
IServiceBus serviceBus;
var result = Parse(new Uri(uri1));
serviceBus = ServiceBusFactory.New(sbc =>
{
sbc.UseRabbitMq();
sbc.ReceiveFrom(uri1);
sbc.Subscribe(c => c.Consumer<SendEmailConsumer>());
});
IPublish publishMessage = new MassTransitPublisher(uri1);
publishMessage.Publish(new SendEmail
{
EmailFrom = "*@8.co.za",
EmailTo = "*@*.co.za",
Subject = "hello",
Body = "hello"
});
Console.ReadKey();
JobRunner jobRunner = new JobRunner();
jobRunner.Start();
Console.ReadKey();
}`
任何幫助將不勝感激,或者我可以嘗試使其正常工作。
您使用的是哪個版本的大眾運輸?
我們刪除了從 Uri 聲明用戶名和密碼的功能(因此它不會出現在日志中),您必須通過 API 來完成。
請參閱https://groups.google.com/d/msg/masstransit-discuss/4m5Vf04oRWM/hujvVh1HSdwJ 。
sbc.UseRabbitMq(x =>
x.ConfigureHost("rabbitmq://yourhost/yourvhost/yourqueue",
x=> x.UserName,
x.Password))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.