TenantConsumeFilter<TKey> class
Namespace: Tenantry.Pro.MassTransit.Filters · Package: Tenantry.Pro.MassTransit · API reference
MassTransit pipeline filter that restores the tenant scope when a message is consumed.
The filter reads the tenantry-tenant-id message header set by TenantPublishFilter<TKey> or TenantSendFilter<TKey>, looks the tenant up in ITenantStore<TKey>, and activates a tenant scope for the duration of the consumer's execution.
If no header is present, or the tenant cannot be found, the message is processed without a tenant scope — the consumer sees no active tenant.
Wire this filter into the bus configuration via cfg.UseTenantryPro<TKey>(ctx).
public sealed class TenantConsumeFilter<TKey> : IFilter<ConsumeContext>, IProbeSite where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters
TKey: The tenant identifier type.
Implements IFilter<ConsumeContext>, IProbeSite.
Constructors
TenantConsumeFilter(ITenantScope<TKey>, ITenantStoreAccessor<TKey>, MissingTenantBehavior, ILogger<TenantConsumeFilter<TKey>>)
MassTransit pipeline filter that restores the tenant scope when a message is consumed.
public TenantConsumeFilter(ITenantScope<TKey> tenantScope, ITenantStoreAccessor<TKey> storeAccessor, MissingTenantBehavior onMissingTenant, ILogger<TenantConsumeFilter<TKey>> logger)Parameters:
tenantScopeITenantScope<TKey>: Runs each consumer under the message's tenant.storeAccessorITenantStoreAccessor<TKey>: Looks up the message's tenant before it is consumed.onMissingTenantMissingTenantBehavior: What to do with a message that carries no tenant, or one the store does not know.loggerILogger<TenantConsumeFilter<TKey>>: Logs messages consumed without a tenant.
The filter reads the tenantry-tenant-id message header set by TenantPublishFilter<TKey> or TenantSendFilter<TKey>, looks the tenant up in ITenantStore<TKey>, and activates a tenant scope for the duration of the consumer's execution.
If no header is present, or the tenant cannot be found, the message is processed without a tenant scope — the consumer sees no active tenant.
Wire this filter into the bus configuration via cfg.UseTenantryPro<TKey>(ctx).
Methods
Probe(ProbeContext)
Adds this filter to MassTransit's diagnostic probe, which describes the consume pipeline.
public void Probe(ProbeContext context)Parameters:
contextProbeContext: The probe context to add to.
Send(ConsumeContext, IPipe<ConsumeContext>)
Sends a context to a filter, such that it can be processed and then passed to the specified output pipe for further processing.
public Task Send(ConsumeContext context, IPipe<ConsumeContext> next)Parameters:
contextConsumeContext: The pipe context typenextIPipe<ConsumeContext>: The next pipe in the pipeline
Returns: Task: An awaitable Task
MassTransitProBuilderExtensions class
Extension methods for registering MassTransit tenant-propagation services on ProBuilder<TKey>tenantry-pro-internal-probuilder.md.
TenantPublishFilter<TKey> class
MassTransit pipeline filter that adds the current tenant ID as a message header when a message is published.