Exchange 绑定在 MassTransit 与 RabbitMQ 和 SignalR 中不起作用 [英] Exchange binding not working in MassTransit with RabbitMQ and SignalR

查看:35
本文介绍了Exchange 绑定在 MassTransit 与 RabbitMQ 和 SignalR 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用大众运输rabbitMQ 和signalR 实现了一个.net 核心web api,我正在尝试使signalR 背板工作.我怀疑问题出在大众运输为我解决的交换绑定上,但我无法弄清楚我做错了什么导致这种行为.

I have implemented a .net core web api with masstransit rabbitMQ and signalR and im trying to make signalR backplane work. I suspect the problem is with exchange bindings that masstransit solves for me but i cant figure out what im doing wrong to have this behaviour.

我的目标是能够拥有另一个应用程序将调用的端点(现在我使用邮递员为此),它将向所有客户端(js 端)发布消息,但每当消息发布并到达时由于没有绑定,因此交换没有任何反应.

My goal here is to be able to have an endpoint that another app will call (for now im using postman for this) that will publish a message to all the clients (js side) but whenever the message is published and it arrives to the exchange nothing happens since there is no binding.

在rabbitMQ 管理工具中,它创建一个交换而没有任何绑定到另一个交换/队列

In rabbitMQ management tools it creates an exchange without any binding to another exchange/queue

我的启动:

        public void ConfigureServices(IServiceCollection services)
    {
        Utilities utilities = new Utilities(Configuration);

        RabbitMQIdentity rabbitMQIdentity = utilities.GetRabbitMQIdentity();
        var username = rabbitMQIdentity.UserName;
        var password = rabbitMQIdentity.Password;
        var hostName = rabbitMQIdentity.HostName;
        var portNumber = rabbitMQIdentity.Port;

        services.AddHttpClient();
        services.AddControllers();
        services.AddSignalR();

        services.AddMassTransit(config =>
        {
            config.AddSignalRHub<NotificationHub>();
            config.UsingRabbitMq((ctx, cfg) =>
            {
                cfg.Host($"amqp://{username}:{password}@{hostName}:{portNumber}");
                cfg.ConfigureEndpoints(ctx);
            });
        });
        services.AddMassTransitHostedService();

        services.AddSingleton<IHostEnvironment>(hostEnvironment);
        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        services.AddSingleton<LogConfigurationUtility, WebLogConfigurationUtility>();
        services.AddCors(options =>
        {
            options.AddDefaultPolicy(builder =>
            {
                builder.SetIsOriginAllowed((x) => Configuration["CorsWhiteList"].Split(';').Any(x.Contains))
                       .WithMethods("GET", "POST")
                       .AllowAnyHeader()
                       .AllowCredentials();
            });
        });
    }

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseCors();

        app.UseMiddleware<RequestMiddleware>();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapHub<NotificationHub>("/notificationhub");
        });
    }

我的发布方法:

IReadOnlyList<IHubProtocol> protocols = new IHubProtocol[] { new JsonHubProtocol() };


        publishEndpoint.Publish<All<NotificationHub>>(new
        {
            Messages = protocols.ToProtocolDictionary("Notify", new object[] { "backend-process", "oiiiii" })
        });

还有我的客户端:

useEffect(() => {
    $(function() {
        const connection = new HubConnectionBuilder()
            .withUrl(hubUrl)
            .configureLogging(LogLevel.Trace)
            .build();
        // Create a function that the hub can call to broadcast messages.
        connection.on("Notify", (status) => {
            console.log("entrouuuuuu");
            setNotification(status);
        });
        // Start the connection.
        async function start() {
            try {
                await connection.start();
                connection.invoke("InitializeClient", orderId);
                console.log("SignalR Connected.");
            } catch (err) {
                setTimeout(start, 5000);
            }
        }

        start();
    });
}, []);

我遵循了官方的 MassTransit 文档并试图找出示例示例与我的不同之处,但我似乎无法弄清楚(除了正确创建和绑定交换之外).

I have followed the official MassTransit documentation and tried to figure out what the sample example differs from mine but i cant seem to be able to figure it out (apart from creating and binding the exchanges correctly).

https://masstransit-project.com/advanced/signalr/quickstart.htmlhttps://masstransit-project.com/advanced/signalr/sample.html

有人可以帮我吗?

推荐答案

7.1.6 中存在一个错误 已修复,将在 7.1.7 中发布.

There is a bug in 7.1.6 that has been fixed and will be released in 7.1.7.

这篇关于Exchange 绑定在 MassTransit 与 RabbitMQ 和 SignalR 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆