Esempio n. 1
0
        public override async Task PublishMessageAsync(IMessage message, CancellationToken cancellationToken)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            // Only process messages for which there are defined exchanges.
            Type messageType = message.GetType();

            if (!PublisherModule.IsExchangeMessage(messageType))
            {
                return;
            }

            // Lookup the exchange associated with the message and the bus
            // on which it should be created.
            ExchangeMeta definition = PublisherModule.GetDefinition(messageType);
            IBus         bus        = BusModule.GetBus(definition.BusName);

            // Create the exchange/queue:
            CreatedExchange createdExchange = await CreateExchange(bus, definition).ConfigureAwait(false);

            LogPublishedMessage(createdExchange, message);

            // Publish the message to the created exchange/queue.
            await definition.PublisherStrategy.Publish(this, createdExchange,
                                                       message,
                                                       cancellationToken);
        }
Esempio n. 2
0
 private void LogPublishedMessage(CreatedExchange exchange, IMessage message)
 {
     Logger.LogTraceDetails(RabbitMqLogEvents.PublisherEvent,
                            "Message being Published to Message Bus.",
                            new {
         exchange.Definition.BusName,
         exchange.Definition.ExchangeName,
         exchange.Definition.QueueMeta?.QueueName,
         exchange.Definition.ContentType,
         Message = message
     });
 }