Azure 接收方未接收到与公共交通有关的邮件-订阅

Azure 接收方未接收到与公共交通有关的邮件-订阅,azure,masstransit,servicebus,Azure,Masstransit,Servicebus,我正在使用下面的代码将MassTransit设置为使用ServiceBus private static ServiceProvider SetupServiceCollection() { var connectionString = ConfigurationManager.AppSettings["AzureServiceBusConnectionString"]; var services = new ServiceCollection()

我正在使用下面的代码将MassTransit设置为使用ServiceBus

private static ServiceProvider SetupServiceCollection()
{
    var connectionString = ConfigurationManager.AppSettings["AzureServiceBusConnectionString"];
    var services = new ServiceCollection()
        .AddMassTransit(x =>
        {
            x.UsingAzureServiceBus((context, cfg) =>
            {
                cfg.Host(connectionString);
                cfg.ConfigureEndpoints(context);
                cfg.Message<MyMessage>(x =>
                {
                    x.SetEntityName("my-topic");
                });
            });
        });

    return services.BuildServiceProvider(); 
}
我希望我的信息只发送到我的主题

但是,MassTransit正在创建主题,名称似乎是使用类型名称生成的。我怎样才能完全阻止这一切

我正在如下设置接收器

public static void SetupMassTransit(this ServiceCollection services, string connectionString)
{
    services.AddMassTransit(x =>
    {
        x.UsingAzureServiceBus((context, cfg) =>
        {
            cfg.Host(connectionString);
            cfg.ConfigureEndpoints(context);
            x.UsingAzureServiceBus((context, cfg) =>
            {
                cfg.Host(connectionString);
                cfg.SubscriptionEndpoint<MyMessage>("low", e =>
                {
                    e.Consumer<MyMessageConsumer>(context);
                    e.PrefetchCount = 100;
                    e.MaxConcurrentCalls = 100;
                    e.LockDuration = TimeSpan.FromMinutes(5);
                    e.MaxAutoRenewDuration = TimeSpan.FromMinutes(30);
                    e.UseMessageRetry(r => r.Intervals(100, 200, 500, 800, 1000));
                    e.UseInMemoryOutbox();
                    e.ConfigureConsumeTopology = false;
                });
        });
    });
}
public static void SetupMassTransit(此服务集合服务,字符串连接字符串)
{
services.AddMassTransit(x=>
{
x、 使用AzuReserveCebus((上下文,cfg)=>
{
主机(connectionString);
配置端点(上下文);
x、 使用AzuReserveCebus((上下文,cfg)=>
{
主机(connectionString);
cfg.SubscriptionEndpoint(“低”,e=>
{
e、 消费者(语境);
e、 预取计数=100;
e、 MaxConcurrentCalls=100;
e、 锁定持续时间=从分钟开始的时间跨度(5);
e、 MaxAutoRenewDuration=时间跨度从分钟(30);
e、 UseMessageRetry(r=>r.interval(1002005008001000));
e、 使用memoryoutbox();
e、 configureconsumertopology=false;
});
});
});
}
我可以看到消息被正确发送,如服务总线资源管理器中的订阅中所示。但是,接收者没有接收到消息?没有错误或发生任何事情?真令人沮丧


Paul

您正在调用
ConfigureEndpoints
,默认情况下,它将为已添加的使用者、sagas等创建接收端点。但是,您的代码示例不显示任何
.AddConsumer
方法。如果没有任何使用者,请不要调用
ConfigureEndpoints

对于您的接收器,您应该使用:

public static void SetupMassTransit(this ServiceCollection services, string connectionString)
{
    services.AddMassTransit(x =>
    {
        x.AddConsumer<MyMessageConsumer>();
        
        x.UsingAzureServiceBus((context, cfg) =>
        {
            cfg.Host(connectionString);

            cfg.SubscriptionEndpoint("your-topic-name", "your-subscription-name", e =>
            {
                e.PrefetchCount = 100;
                e.MaxConcurrentCalls = 100;
                e.LockDuration = TimeSpan.FromMinutes(5);
                e.MaxAutoRenewDuration = TimeSpan.FromMinutes(30);

                e.UseMessageRetry(r => r.Intervals(100, 200, 500, 800, 1000));
                e.UseInMemoryOutbox();

                e.ConfigureConsumer<MyMessageConsumer>(context);
            });
        });
    });
}
然后,使用上面创建的
IServiceProvider
发布:

var bus = serviceProvider.GetRequiredService<IBus>();
var endpoint = await bus.GetSendEndpoint(new Uri("topic:your-topic-name"));
await endpoint.Send(new MyMessage());
var bus=serviceProvider.GetRequiredService();
var endpoint=await bus.GetSendEndpoint(新Uri(“主题:您的主题名称”);
等待endpoint.Send(newmymessage());

这应该可以满足您所需的最低要求。

我已经添加了更多信息,队列和主题仍在创建中。如果您不想使用队列,请使用。MassTransit的文档非常令人沮丧,太多的部分示例,比如这一个,他们使用了一个名为provider的变量,但没有说明它在哪里omes from我删除了ConfigureEndpoints,主题仍在创建中接收方也没有接收到消息
private static ServiceProvider SetupServiceCollection()
{
    var connectionString = ConfigurationManager.AppSettings["AzureServiceBusConnectionString"];
    var services = new ServiceCollection()
        .AddMassTransit(x =>
        {
            x.UsingAzureServiceBus((context, cfg) =>
            {
                cfg.Host(connectionString);
            });
        });

    return services.BuildServiceProvider(); 
}
var bus = serviceProvider.GetRequiredService<IBus>();
var endpoint = await bus.GetSendEndpoint(new Uri("topic:your-topic-name"));
await endpoint.Send(new MyMessage());