如何在CloudAMQP上将MassTransit与RabbitMq连接

时间:2019-05-12 20:29:37

标签: c# rabbitmq masstransit cloudamqp

我在将MassTransit与CloudAMQP上的RabbitMq连接时遇到问题。下面是我的代码

var bus = Bus.Factory.CreateUsingRabbitMq(otions => {
    var host = otions.Host(new Uri("rabbitmq://llama-01.rmq.cloudamqp.com"),
    h => { h.Username("my_username"); h.Password("my_password"); });
    otions.ReceiveEndpoint(host, "recvqueue", ep => {
        ep.Handler<Communicate>(Handle);
    });
});

bus.Start();

h.Passwordh.Username是正确的。 当我尝试启动公共汽车时,出现以下错误:

  

RabbitMQ连接失败:代理无法访问:   my_username@llama-01.rmq.cloudamqp.com:5672 /

我怀疑问题出在URI地址,但我找不到正确的地址。

1 个答案:

答案 0 :(得分:1)

好吧,我快速浏览了他们的入门指南,发现您的实例获得了一个与您的用户同名的虚拟主机。

enter image description here

上面的图片是我订阅免费计划后得到的。

对于MassTransit,您需要在连接字符串的末尾添加虚拟主机,例如const imgDic = { 0: item_1, 1: item_1_alt, 2: item_1_alt2, 3: item_1_alt3, 4: item_1_alt4, 5: item_1_alt5 }; class Buy_Item extends React.Component { constructor(props) { this.state = { radioStatus: null, currentImg: item_1 }; this.handleRadioClick = this.handleRadioClick.bind(this); } handleRadioClick(radioId) { this.setState({ radioStatus: radioId, currentImg: imgDic[radioId] }); } render() { // the rest of render code goes here... } } ,或者在主机配置中配置虚拟主机以及用户名和密码。