Docs
Tenantry ProAPI reference

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:

  • tenantScope ITenantScope<TKey>: Runs each consumer under the message's tenant.
  • storeAccessor ITenantStoreAccessor<TKey>: Looks up the message's tenant before it is consumed.
  • onMissingTenant MissingTenantBehavior: What to do with a message that carries no tenant, or one the store does not know.
  • logger ILogger<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:

  • context ProbeContext: 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:

  • context ConsumeContext: The pipe context type
  • next IPipe<ConsumeContext>: The next pipe in the pipeline

Returns: Task: An awaitable Task

On this page