Ejemplo 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);
        }
Ejemplo 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
     });
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Logs the provided deserialized message and the information about the exchange and
 /// queue from which it was received.
 /// </summary>
 /// <param name="message">The received message.</param>
 public void LogReceivedMessage(IMessage message)
 {
     Logger.LogTraceDetails(RabbitMqLogEvents.SubscriberEvent,
                            "Message Received from Message Bus.",
                            new {
         Bus      = Subscriber.QueueMeta.Exchange.BusName,
         Exchange = Subscriber.QueueMeta.Exchange.ExchangeName,
         Queue    = Subscriber.QueueMeta.QueueName,
         MessageProps.ContentType,
         Consumer = Subscriber.DispatchInfo.ConsumerType.Name,
         Handler  = Subscriber.DispatchInfo.MessageHandlerMethod.Name,
         Message  = message
     });
 }