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

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

问题描述

我已经使用masstransit 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.html https://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绑定在RabbitMQ和SignalR的MassTransit中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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