コード例 #1
0
        public static Message GenerateMessage(object payload, MessageProperties messageSpecificProperties, IMessageGenerator messageGenerator = null)
        {
            messageGenerator = messageGenerator ?? new MessageGenerator();
            var message = messageGenerator.GenerateMessage(payload);

            var messageType = payload.GetType();

            message.MessageId   = Guid.NewGuid().ToString();
            message.ContentType = messageType.SimpleQualifiedName();
            message.UserProperties["MessageType"] = messageType.FullName;

            message.PopulateCorrelationId(
                messageSpecificProperties?.CorrelationIdProvider.CorrelationId);

            message.AddProperties(messageSpecificProperties?.CustomProperties);

            return(message);
        }
コード例 #2
0
        private IOperationMessage GenerateReferenceOfMessage(IEnumerable <MessageAttribute> messageAttributes, SchemaRepository schemaRepository, MessageRepository messageRepository)
        {
            // https://www.asyncapi.com/docs/specifications/2.0.0#operationObject
            var messages = messageAttributes.Select(messageAttribute =>
            {
                var payloadType = messageAttribute.PayloadType;
                _schemaGenerator.GenerateSchema(payloadType, schemaRepository);
                _messageGenerator.GenerateMessage(payloadType, messageRepository, messageAttribute);
                return(new Reference(_options.SchemaIdSelector(payloadType), ReferenceType.Message));
            }).ToList();

            if (messages.Count > 1)
            {
                return(new MultipleMessage {
                    OneOf = messages
                });
            }
            else
            {
                return(messages.Single());
            }
        }
コード例 #3
0
        private Message GenerateMessage(object payload, MessageProperties messageSpecificProperties, string subscriber)
        {
            var message = _messageGenerator.GenerateMessage(payload);

            var messageType = payload.GetType();

            message.MessageId   = Guid.NewGuid().ToString();
            message.ContentType = messageType.SimpleQualifiedName();
            message.UserProperties["MessageType"] = messageType.FullName;

            message.PopulateCorrelationId(
                messageSpecificProperties?.CorrelationIdProvider.CorrelationId
                ?? _defaultMessageProperties.CorrelationIdProvider.CorrelationId);

            message.AddProperties(_defaultMessageProperties.CustomProperties);
            message.AddProperties(messageSpecificProperties?.CustomProperties);

            if (!string.IsNullOrEmpty(subscriber))
            {
                message.UserProperties["SpecificSubscriber"] = subscriber;
            }

            return(message);
        }