public async Task PublishAsync <TMessage>(TMessage message, CancellationToken cancellationToken = default, Action <MessagingEnvelope> envelopeCustomizer = null, string topicName = null) { var outgoingEnvelope = PrepareMessageEnvelope(message, envelopeCustomizer); var key = (message as IKeyProvider)?.Key; var value = _messageSerDes.SerializeMessageEnvelope(outgoingEnvelope); var newTopicName = _topicRegistry.GetTopicForName(topicName) ?? _topicRegistry.GetTopicForMessageType(message.GetType()); await _topicPublisher.PublishAsync(newTopicName, key, value, cancellationToken); await Task.Yield(); }
public async Task PublishAsync <T>(T message, MessagingPublisherOptions publisherOptions = null, CancellationToken cancellationToken = default) { var outgoingEnvelope = PrepareMessageEnvelope(message, publisherOptions?.EnvelopeCustomizer); var envelopeData = _messageSerDes.SerializeMessageEnvelope(outgoingEnvelope); var newTopicName = _topicRegistry.GetTopicForName(publisherOptions?.TopicName) ?? _topicRegistry.GetTopicForMessageType(message.GetType()); await _messagingTransport.PublishAsync(newTopicName, envelopeData, cancellationToken); _logger.LogDebug("Messaging publisher sent a message for subject {Subject}", newTopicName); await Task.Yield(); }