private void AddSerializer( IDictionary <string, IBrokerSerializer> serializers, IBrokerSerializer serializer) { if (!serializers.Keys.Contains(serializer.ContentType)) { serializers[serializer.ContentType] = serializer; } }
public byte[] Serialize(object value, string contentType) { Check.NotNull(value, nameof(value)); Check.NotNullOrWhiteSpace(contentType, nameof(contentType)); IBrokerSerializer serializer = GetSerializer(contentType); return(serializer.Serialize(value)); }
public T Deserialize <T>(string contentType, byte[] value) { Check.NotNullOrWhiteSpace(contentType, nameof(contentType)); Check.NotNull(value, nameof(value)); IBrokerSerializer serializer = GetSerializer(contentType); return(serializer.Deserialize <T>(value, typeof(T))); }
public object Deserialize(string contentType, Type valueType, byte[] value) { Check.NotNullOrWhiteSpace(contentType, nameof(contentType)); Check.NotNull(valueType, nameof(valueType)); Check.NotNull(value, nameof(value)); IBrokerSerializer serializer = GetSerializer(contentType); return(serializer.Deserialize(value, valueType)); }
public MessageBrokerSetup() { _messageSerializer = new JsonBrokerSerializer(); ILoggerFactory loggerFactory = new TestLoggerFactory(); this.MockMsgModule = new Mock <IMessagingModule>(); this.Instance = new MockMessageBroker(loggerFactory, this.MockMsgModule); }
private IBrokerSerializer GetSerializer(string contentType) { IBrokerSerializer serializer = null; if (!_serializers.TryGetValue(contentType, out serializer)) { throw new BrokerException($"Serializer for Content Type: {contentType} not registered."); } return(serializer); }
public byte[] Serialize(IMessage message, params string[] contentTypes) { Check.NotNull(message, nameof(message)); string contentType = GetFistContentType(contentTypes); message.SetContentType(contentType); IBrokerSerializer serializer = GetSerializer(contentType); return(serializer.Serialize(message)); }
public RabbitMqClient( IConnection connection, IBrokerSerializer serializer, RabbitMqOptions options, ILogger <RabbitMqClient> logger) { _connection = connection; _serializer = serializer; _logger = logger; _isLoggerEnabled = options.Logger.Enabled; _maxChannels = options.MaxProducerChannels <= 0 ? 1000 : options.MaxProducerChannels; }
public IMessage Deserialize(Type messageType, BasicDeliverEventArgs deliveryEvent) { Check.NotNull(messageType, nameof(messageType)); Check.NotNull(deliveryEvent, nameof(deliveryEvent)); string contentType = deliveryEvent.BasicProperties.ContentType; if (contentType.IsNullOrWhiteSpace()) { throw new BrokerException( $"The content type for a message of type: {messageType} was not " + $"specified as a basic property."); } IBrokerSerializer serializer = GetSerializer(contentType); return(serializer.Deserialize <IMessage>(deliveryEvent.Body, messageType)); }