public static void Update <T>(this IBasicProperties self, MotorCloudEvent <byte[]> cloudEvent,
                                      RabbitMQPublisherConfig <T> config, ICloudEventFormatter cloudEventFormatter)
        {
            var messagePriority = cloudEvent.Extension <RabbitMQPriorityExtension>()?.Priority ??
                                  config.DefaultPriority;

            if (messagePriority.HasValue)
            {
                self.Priority = messagePriority.Value;
            }
            var dictionary = new Dictionary <string, object>();

            foreach (var attr in cloudEvent.GetAttributes())
            {
                if (string.Equals(attr.Key, CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) ||
                    string.Equals(attr.Key,
                                  CloudEventAttributes.DataContentTypeAttributeName(cloudEvent.SpecVersion)) ||
                    string.Equals(attr.Key, RabbitMQPriorityExtension.PriorityAttributeName) ||
                    string.Equals(attr.Key, RabbitMQBindingConfigExtension.ExchangeAttributeName) ||
                    string.Equals(attr.Key, RabbitMQBindingConfigExtension.RoutingKeyAttributeName))
                {
                    continue;
                }
                dictionary.Add($"{CloudEventPrefix}{attr.Key}",
                               cloudEventFormatter.EncodeAttribute(cloudEvent.SpecVersion, attr.Key, attr.Value,
                                                                   cloudEvent.GetExtensions().Values));
            }

            self.Headers = dictionary;
        }
        public async Task PublishMessageAsync(MotorCloudEvent <byte[]> cloudEvent, CancellationToken token = default)
        {
            if (!_connected)
            {
                await StartAsync();
            }
            if (Channel == null)
            {
                throw new InvalidOperationException("Channel is not created.");
            }
            var properties = Channel.CreateBasicProperties();

            properties.DeliveryMode = 2;
            properties.Update(cloudEvent, _config, _cloudEventFormatter);

            var publishingTarget = cloudEvent.Extension <RabbitMQBindingConfigExtension>()?.BindingConfig ??
                                   _config.PublishingTarget;

            Channel.BasicPublish(publishingTarget.Exchange, publishingTarget.RoutingKey, true, properties,
                                 cloudEvent.TypedData);
        }
示例#3
0
 public async Task PublishMessageAsync(MotorCloudEvent <byte[]> cloudEvent, CancellationToken token = default)
 {
     var topic = cloudEvent.Extension <KafkaTopicExtension>()?.Topic ?? config.Topic;
     await producer.ProduceAsync(topic,
                                 new KafkaCloudEventMessage(cloudEvent, ContentMode.Binary, _cloudEventFormatter), token);
 }