简体   繁体   English

Masstransit - Rabbit MQ 虚拟主机

[英]Masstransit - Rabbit MQ virtual host

I am using mass transit and connecting to my rabbit broker.我正在使用公共交通并连接到我的兔子经纪人。

 string uri1 = @"rabbitmq://myusername:mypassword@myip/myvirtualhost/myqueue";

I keep getting a ConfigurationException was unhandled.我不断收到未处理的 ConfigurationException。

An exception was thrown during service bus creation {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} {"Failed to start bus services"} at MassTransit.ServiceContainer.Start() in d:\\BuildAgent-03\\work\\aa063b4295dfc097\\src\\MassTransit\\ServiceContainer.cs:line 83 at MassTransit.ServiceBus.Start() in d:\\BuildAgent-03\\work\\aa063b4295dfc097\\src\\MassTransit\\ServiceBus.cs:line 369 at MassTransit.Builders.ServiceBusBuilderImpl.Build() in d:\\BuildAgent-03\\work\\aa063b4295dfc097\\src\\MassTransit\\Configuration\\Builders\\ServiceBusBuilderImpl.cs:line 84 at MassTransit.BusConfigurators.ServiceBusConfiguratorImpl.CreateServiceBus() in d:\\BuildAgent-03\\work\\aa063b4295dfc097\\src\\MassTransit\\Configuration\\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服务总线创建过程中抛出异常 {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

What really odd is that it works without specifying the virtual host but them offcourse goes to the wrong virtual host.真正奇怪的是,它在没有指定虚拟主机的情况下工作,但它们偏离了错误的虚拟主机。

I then downloaded the rabbitMQ library and it connected fine to the right virtual host with my credentials.然后我下载了 rabbitMQ 库,它使用我的凭据很好地连接到正确的虚拟主机。 This is how I know my credentials, virtual host is set up fine.这就是我知道我的凭据的方式,虚拟主机设置得很好。 I even added a queue in case that was the problem.我什至添加了一个队列以防万一。 Is there some bug in Masstransit? Masstransit 中是否存在一些错误? I really dont see what im doing wrong.我真的不明白我做错了什么。 I'm contemplating not using masstransit and programming my own lightweight version.我正在考虑不使用大众运输并编写我自己的轻量级版本。

I even copied pasted this into https://github.com/MassTransit/MassTransit/blob/v2.7.2/src/Transports/MassTransit.Transports.RabbitMq/RabbitMqEndpointAddress.cs#L167 my solution to check if it is trimming the virtual host correctly and it is.我什至将其复制粘贴到https://github.com/MassTransit/MassTransit/blob/v2.7.2/src/Transports/MassTransit.Transports.RabbitMq/RabbitMqEndpointAddress.cs#L167我的解决方案以检查它是否正在修剪虚拟主机正确,它是。 I'm really confused.我真的很困惑。 ` static readonly Regex regex = new Regex(@"^[A-Za-z0-9- .:]+$"); ` 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();
    }`

Any help would be appreciated or anything else I can try to get this working.任何帮助将不胜感激,或者我可以尝试使其正常工作。

What version of MassTransit are you using?您使用的是哪个版本的大众运输?

We removed the ability to declare the username and password from the Uri (so it doesn't appear in the logs) and you must do it via the API.我们删除了从 Uri 声明用户名和密码的功能(因此它不会出现在日志中),您必须通过 API 来完成。

See https://groups.google.com/d/msg/masstransit-discuss/4m5Vf04oRWM/hujvVh1HSdwJ .请参阅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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM