控制公共交通交换和绑定

Control Masstransit Exchanges and Bindings

我正在使用公共交通工具。我想避免为端点创建交换,而宁愿让端点队列直接绑定到发布交换。

这是我的代码

    cfg.Message<Notification>(x => { x.SetEntityName("NOTIFICATION_REQUEST"); });

    g.ReceiveEndpoint("notification-workerQ", e =>        
    {
         e.Consumer<NotificationConsumer>();
    });

这创造了

有没有办法避免 notification-workerQ 交换并让队列直接绑定到 NOTIFICATION_REQUEST 交换?

补充问题

我被要求完全不创建交换,而是使用一个已经存在的主题交换,我使用路由键将我的队列绑定到该交换。

这意味着我的 notification-workerQ 应该使用像“componentX.something.notification”这样的路由键绑定到 GENERIC_DROP exchange

也许像

    g.ReceiveEndpoint("notification-workerQ", e =>        
    {
         e.Consumer<NotificationConsumer>(x => 
         { 
            //THIS IS NOT WORKING CODE
            x.consumeFrom("GENERIC_DROP", "ROUTING_KEY") 
         });
    });

无法阻止 MassTransit 创建 notification-workerQ 交换,因为 MassTransit 总是为队列创建匹配的交换。

但是,您可以通过如下所示配置接收端点,将现有主题交换与路由密钥绑定。

e.Bind("NOTIFICATION_REQUEST", x =>
{
    x.RoutingKey = "ROUTING_KEY";
    x.ExchangeType = ExchangeType.Topic;
});

There is also a sample that shows how to use direct exchanges, topic exchanges are configured the same way.