コード例 #1
0
ファイル: MessageBusPublisher.cs プロジェクト: VCuzmin/nbb
        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();
        }
コード例 #2
0
ファイル: MessageBusPublisher.cs プロジェクト: hfz-r/nbb
        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();
        }