Пример #1
0
        private IRabbitPublishMessageWrapper <T> WrappingMessage <T>(T message, RabbitPublishMessageMetadata metadata)
        {
            switch (metadata.SerializeType)
            {
            case PublishMessageSerialzeType.Proto: return(new RabbitPublishMessageProtoWrapper <T>(message, metadata));

            case PublishMessageSerialzeType.Json: return(new RabbitPublishMessageJsonWrapper <T>(message, metadata));
            }
            return(new RabbitPublishMessageProtoWrapper <T>(message, metadata));
        }
Пример #2
0
        private RabbitPublishMessageMetadata GetOrCreateNewPublishInfo <T>(T message)
        {
            if (_publishDic.TryGetValue(message.GetType().FullName.ToLower(), out var metadata) && metadata != null)
            {
                return(metadata);
            }

            var attribute = message.GetType().GetCustomAttribute <RabbitPublishToAttribute>();

            Ensure.NotNull(attribute, "The message cannot be found metadata info, please set RabbitPublishToAttribute to it!");

            var hostSetting = _rabbitMQSetting.GetServer(attribute.GroupName);

            Ensure.NotNull(hostSetting, "The message cannot be found host setting, please set it at the RabbitPublishToAttribute!");

            metadata = new RabbitPublishMessageMetadata(attribute, hostSetting);
            _publishDic.Add(message.GetType().FullName.ToLower(), metadata);
            return(metadata);
        }