Skip to content

Commit

Permalink
Remove tenant context validation for DLQ publishing (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraliv13 authored Jan 12, 2022
1 parent baf4c9c commit b16ec22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace NBB.Messaging.Abstractions
{
public class DefaultDeadLetterQueue : IDeadLetterQueue
{
public const string ErrorTopicName = "_error";

private readonly IMessageBusPublisher _messageBusPublisher;
private readonly IMessageSerDes _messageSerDes;
private readonly ILogger<DefaultDeadLetterQueue> _logger;
Expand Down Expand Up @@ -46,7 +48,7 @@ public void Push(MessagingEnvelope messageEnvelope, string topicName, Exception

// Fire and forget
_ = _messageBusPublisher
.PublishAsync(payload, MessagingPublisherOptions.Default with { TopicName = "_error" }, default)
.PublishAsync(payload, MessagingPublisherOptions.Default with { TopicName = ErrorTopicName }, default)
.ContinueWith(t => _logger.LogError(t.Exception, "Error publishing to dead letter queue"), TaskContinuationOptions.OnlyOnFaulted);

}
Expand Down Expand Up @@ -93,7 +95,7 @@ private void Push(byte[] messageData, string topicName, Exception ex)

// Fire and forget
_ = _messageBusPublisher
.PublishAsync(payload, MessagingPublisherOptions.Default with { TopicName = "_error" }, default)
.PublishAsync(payload, MessagingPublisherOptions.Default with { TopicName = ErrorTopicName }, default)
.ContinueWith(t => _logger.LogError(t.Exception, "Error publishing to dead letter queue"), TaskContinuationOptions.OnlyOnFaulted);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public MultiTenancyMessageBusPublisherDecorator(IMessageBusPublisher inner,
public async Task PublishAsync<T>(T message, MessagingPublisherOptions options = null,
CancellationToken cancellationToken = default)
{
if (options?.TopicName == DefaultDeadLetterQueue.ErrorTopicName)
{
await _inner.PublishAsync(message, options , cancellationToken);
return;
}

var tenantId = _tenantContextAccessor.TenantContext.GetTenantId();
options ??= MessagingPublisherOptions.Default;

Expand All @@ -35,4 +41,4 @@ void NewCustomizer(MessagingEnvelope outgoingEnvelope)
await _inner.PublishAsync(message, options with {EnvelopeCustomizer = NewCustomizer}, cancellationToken);
}
}
}
}

0 comments on commit b16ec22

Please sign in to comment.