.net-core - MassTransit SignalR 绑定
问题描述
我在设置 MassTransit SignalR 解决方案时遇到了一些问题。我之前发布了一个关于 Chris 回答并帮助我的绑定的问题,但是在更新包之后(我仍在使用 6.xx,它有其他问题,例如重新启动 RabbitMQ 服务会在发送消息时出现错误)我的绑定没有似乎工作正常了。
这是我问的第一个问题:Exchange binding not working in MassTransit with RabbitMQ and SignalR
现在我已经更新到 7.1.7 并且还更新了已弃用的方法。这就是我的 Startup 的样子:
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(e => {
e.EnableDetailedErrors = true;
e.MaximumReceiveMessageSize = 102400000;
});
services.AddMassTransit(x =>
{
x.AddSignalRHub<NotificationHub>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.Host($"amqp://{username}:{password}@{hostName}:{portNumber}");
cfg.AutoDelete = true;
cfg.Durable = false;
cfg.QueueExpiration = TimeSpan.FromMinutes(10);
cfg.ConfigureEndpoints(context);
});
});
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();
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
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");
});
}
这是我的发布:
logger.LogInformation($"MassTransit publishing group message. GroupName:{paymentCallback.OrderId} ; Message:{paymentCallback.Event}");
IReadOnlyList <IHubProtocol> protocols = new IHubProtocol[] { new JsonHubProtocol() };
publishEndpoint.Publish<Group<NotificationHub>>(
new GroupHub<NotificationHub>()
{
GroupName = paymentCallback.OrderId,
Messages = protocols.ToProtocolDictionary("Notify", new object[] { paymentCallback.Event })
},
context => context.TimeToLive = TimeSpan.FromMinutes(10)
);
和客户:
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();
});
所以现在,在 RabbitMQ 管理工具中,我可以看到正在创建的交换,但它再次没有绑定,也没有队列。克里斯仍然存在同样的问题吗?还是我做错了什么?
谢谢您的帮助!
解决方案
推荐阅读
- python - Flask SQLAlchemy - 如何按 ForeignKey 变量的计数排序查询结果
- sql - SQL Server:如何创建一个作业,每次添加一行时,该作业将从一行中获取一个字段并将其推送到另一个表
- pandas - 将 pandas 列转换为具有异常最大值的日期时间
- laravel - php artisan workerman:传递附加参数“start”时找不到服务器
- xml - 使用 XSLT 从平面 XML 创建嵌套 XML
- visual-studio - 当可见性设置为展开时,将 SumLookUp 与 LookUpSet 一起使用会产生 #Error
- apache-spark - 如何在databricks中设置环境变量?
- python - Running perl script in lambda function with python3.6 runtime
- php - Convert a string to a formatted array
- c - 在输出 printf 语句时遇到问题