Exemple #1
0
        public PayloadDescriptor Create(object message, Metadata headers)
        {
            var registration = _outgoingMessageRegistry.GetRegistration(message);

            if (registration == null)
            {
                throw new InvalidOperationException($"No outgoing message registered for '{message.GetType().Name}'");
            }

            var messageId = string.IsNullOrEmpty(headers.MessageId) ? _messageIdGenerator.NextMessageId() : headers.MessageId;
            var metadata  = new Metadata(headers.AsEnumerable().ToDictionary(k => k.Key, v => v.Value))
            {
                CausationId   = string.IsNullOrEmpty(headers.CausationId) ? messageId : headers.CausationId,
                CorrelationId = string.IsNullOrEmpty(headers.CorrelationId) ? messageId : headers.CorrelationId,
            };

            return(new PayloadDescriptor(
                       messageId: messageId,
                       topicName: registration.Topic,
                       partitionKey: registration.KeySelector(message),
                       messageType: registration.Type,
                       messageData: message,
                       messageHeaders: metadata.AsEnumerable()
                       ));
        }
        public PayloadDescriptor Create(object message, Metadata headers)
        {
            var registration = _outgoingMessageRegistry.GetRegistration(message);

            if (registration == null)
            {
                throw new InvalidOperationException($"No outgoing message registered for '{message.GetType().Name}'");
            }

            return(new PayloadDescriptor(
                       messageId: _messageIdGenerator.NextMessageId(),
                       topicName: registration.Topic,
                       partitionKey: registration.KeySelector(message),
                       messageType: registration.Type,
                       messageData: message,
                       messageHeaders: headers.AsEnumerable()
                       ));
        }
Exemple #3
0
        public OutgoingMessage Create(object message)
        {
            var registration = _outgoingMessageRegistry.GetRegistration(message);

            if (registration == null)
            {
                throw new InvalidOperationException($"No outgoing message registered for '{message.GetType().Name}'");
            }

            var messageId  = _messageIdGenerator.NextMessageId();
            var rawMessage = SerializeRawMessage(messageId, registration.Type, message);

            return(new OutgoingMessageBuilder()
                   .WithTopic(registration.Topic)
                   .WithMessageId(messageId)
                   .WithKey(registration.KeySelector(message))
                   .WithValue(rawMessage)
                   .WithType(registration.Type)
                   .Build());
        }