我使用Masstransit文档中指定的建议方法在总线创建期间指定RabbitMQ用户名和密码。
以下是总线配置的代码段:
var compensateAddress = BuildQueueUri(Settings.BaseUri, Settings.Compensate);
var ExecuteAddress = BuildQueueUri(Settings.BaseUri, Settings.Execute);
var RabbitMqURI = new Uri(Settings.BaseUri + "/QueueName");
var RabbitMqUsername = Settings.RabbitMqUsername;
var RabbitMqPassword = Settings.RabbitMqPassword;
IServiceBus _bus;
_bus = ServiceBusFactory.New(x =>
{
x.UseRabbitMq(r =>
{
r.ConfigureHost(RabbitMqURI, h =>
{
h.SetUsername(RabbitMqUsername);
h.SetPassword(RabbitMqPassword);
});
});
x.ReceiveFrom(ExecuteAddress);
x.Subscribe(s => s.Instance(_host));
});
当我启动我的应用程序时,我收到以下错误:
“路径可以为空,或者是这些字符的序列:字母,数字,连字符,下划线,句点或冒号。”
可能是什么问题?
Masstransit Version 2.9.0
RabbitMQ.Client版本3.4.0
答案 0 :(得分:1)
这是我能够开始工作的代码 MT 2.10 兔子3.5.3 Erlang 18.0 64bit
public class YourMessage { public string Text { get; set; } }
internal class Program
{
private static void Main(string[] args)
{
var hostAddress = new Uri("rabbitmq://localhost/learningmt_orderservice");
Bus.Initialize(sbc =>
{
sbc.UseRabbitMq(rabbit =>
{
rabbit.ConfigureHost(hostAddress,
chost =>
{
chost.SetUsername("guest");
chost.SetPassword("guest");
});
rabbit.Validate();
});
sbc.ReceiveFrom(hostAddress.AbsoluteUri);
sbc.Subscribe(subs =>
{
subs.Handler<YourMessage>(msg => Console.WriteLine(msg.Text));
});
});
Bus.Instance.Publish(new YourMessage {Text = "Hi"});
}
}