public TypedConsumerService( ILogger <TypedConsumerService <TInput> > logger, IMetricsFactory <TypedConsumerService <TInput> >?metrics, IBackgroundTaskQueue <MotorCloudEvent <TInput> > queue, IMessageDeserializer <TInput> deserializer, IOptions <ContentEncodingOptions> encodingOptions, IEnumerable <IMessageDecoder> decoders, IMessageConsumer <TInput> consumer) { _logger = logger; _queue = queue; _deserializer = deserializer; _consumer = consumer; _consumer.ConsumeCallbackAsync = SingleMessageConsumeAsync; _encodingOptions = encodingOptions.Value; _messageDeserialization = metrics?.CreateSummary("message_deserialization", "Message deserialization duration in ms"); _messageDecoding = metrics?.CreateSummary("message_decoding", "Message decoding duration in ms"); _decoderByEncoding = new Dictionary <string, IMessageDecoder>(); foreach (var decoder in decoders) { _decoderByEncoding[decoder.Encoding] = decoder; } }
public EventStore(IEventDataLayer eventRepository, IConverterRegistry converterRegistry, IMessageDeserializer messageDeserializer, IMediator mediator) { _eventRepository = eventRepository; _converterRegistry = converterRegistry; _messageDeserializer = messageDeserializer; _mediator = mediator; }
IReceivePipe IReceivePipeConfiguration.CreatePipe(IConsumePipe consumePipe, IMessageDeserializer messageDeserializer, Action <IPipeConfigurator <ReceiveContext> > configure) { if (_created) { throw new ConfigurationException("The ReceivePipeConfiguration can only be used once."); } if (configure == null) { DeadLetterConfigurator.UseFilter(new DeadLetterTransportFilter()); _configurator.UseDeadLetter(DeadLetterConfigurator.Build()); ErrorConfigurator.UseFilter(new GenerateFaultFilter()); ErrorConfigurator.UseFilter(new ErrorTransportFilter()); _configurator.UseRescue(ErrorConfigurator.Build(), x => { x.Ignore <OperationCanceledException>(); }); } else { configure(_configurator); } _configurator.UseFilter(new DeserializeFilter(messageDeserializer, consumePipe)); _created = true; return(new ReceivePipe(_configurator.Build(), consumePipe)); }
private TMessage DeserializeAndAcknowledge(IMessage message, IMessageDeserializer <TMessage> deserializer) { var deserializedMessage = DeserializeMessage(message, deserializer); Acknowledge(message); return(deserializedMessage); }
public void SetupSerializationTest() { if (_serializerType == typeof(JsonMessageSerializer)) { Serializer = new JsonMessageSerializer(); Deserializer = new JsonMessageDeserializer(JsonMessageSerializer.Deserializer, Bus, PublishEndpointProvider); } else if (_serializerType == typeof(BsonMessageSerializer)) { Serializer = new BsonMessageSerializer(); Deserializer = new BsonMessageDeserializer(BsonMessageSerializer.Deserializer, Bus, PublishEndpointProvider); } else if (_serializerType == typeof(XmlMessageSerializer)) { Serializer = new XmlMessageSerializer(); Deserializer = new XmlMessageDeserializer(JsonMessageSerializer.Deserializer, Bus, PublishEndpointProvider); } else if (_serializerType == typeof(EncryptedMessageSerializer)) { ISymmetricKeyProvider keyProvider = new TestSymmetricKeyProvider(); var streamProvider = new AesCryptoStreamProvider(keyProvider, "default"); Serializer = new EncryptedMessageSerializer(streamProvider); Deserializer = new EncryptedMessageDeserializer(BsonMessageSerializer.Deserializer, Bus, PublishEndpointProvider, streamProvider); } else if (_serializerType == typeof(BinaryMessageSerializer)) { Serializer = new BinaryMessageSerializer(); Deserializer = new BinaryMessageDeserializer(JsonMessageSerializer.Serializer, Bus, PublishEndpointProvider); } else { throw new ArgumentException("The serializer type is unknown"); } }
public ServerTcpConnection(int id, Socket socket, Action <CommunicationException> connectionFailureHandler, TimeSpan maxUnresponsivenessDuration, IMessageDeserializer messageDeserializer, Action <IMessage, int> messageHandler) : base(id, socket, maxUnresponsivenessDuration, connectionFailureHandler, messageDeserializer) { _messageHandler = messageHandler; }
public void Subscribe <TMessage>( string connectionString, MarketType market, string source, string context, IMessageDeserializer <TMessage> deserializer, Func <TMessage, Task> handler) { var ns = NamespaceMap[market]; var applicationName = "wamphost"; var endpoint = context == null ? string.Empty : $".{context}"; endpoint = $"{applicationName}{endpoint}.{_env}"; var settings = RabbitMqSubscriptionSettings.ForSubscriber(connectionString, ns, source, ns, endpoint); settings.DeadLetterExchangeName = null; var rabbitMqSubscriber = new RabbitMqSubscriber <TMessage>(settings, new DefaultErrorHandlingStrategy(_log, settings)) .SetMessageDeserializer(deserializer) .CreateDefaultBinding() .Subscribe(handler) .SetLogger(_log) .Start(); _stopables.Add(rabbitMqSubscriber); }
protected IReceivePipe CreateReceivePipe(IBusBuilder builder, Func <IConsumePipe, IReceiveEndpointBuilder> endpointBuilderFactory) { IConsumePipe consumePipe = _consumePipe ?? builder.CreateConsumePipe(_consumePipeConfigurator); IReceiveEndpointBuilder endpointBuilder = endpointBuilderFactory(consumePipe); foreach (IReceiveEndpointSpecification specification in _specifications) { specification.Configure(endpointBuilder); } ConfigureAddDeadLetterFilter(builder.SendTransportProvider); var publishEndpointProvider = builder.CreatePublishEndpointProvider(_publishPipeConfigurator); ConfigureRescueFilter(publishEndpointProvider, builder.SendTransportProvider); ISendEndpointProvider sendEndpointProvider = builder.CreateSendEndpointProvider(_sendPipeConfigurator); IMessageDeserializer messageDeserializer = builder.GetMessageDeserializer(sendEndpointProvider, publishEndpointProvider); _receiveConfigurator.UseFilter(new DeserializeFilter(messageDeserializer, consumePipe)); var receivePipe = _receiveConfigurator.Build(); return(new ReceivePipe(receivePipe, consumePipe)); }
public void Subscribe <TMessage>(RabbitConnectionSettings settings, bool isDurable, Func <TMessage, Task> handler, IMessageDeserializer <TMessage> deserializer) { var subscriptionSettings = new RabbitMqSubscriptionSettings { ConnectionString = settings.ConnectionString, QueueName = $"{settings.ExchangeName}.{PlatformServices.Default.Application.ApplicationName}.{settings.RoutingKey ?? "all"}", ExchangeName = settings.ExchangeName, RoutingKey = settings.RoutingKey, IsDurable = isDurable, }; var rabbitMqSubscriber = new RabbitMqSubscriber <TMessage>(subscriptionSettings, new DefaultErrorHandlingStrategy(_logger, subscriptionSettings)) .SetMessageDeserializer(deserializer) .Subscribe(handler) .SetLogger(_logger); if (!_subscribers.TryAdd(subscriptionSettings.QueueName, rabbitMqSubscriber)) { throw new InvalidOperationException( $"A subscriber for queue {subscriptionSettings.QueueName} was already initialized"); } rabbitMqSubscriber.Start(); }
public void Subscribe <TMessage>(RabbitMqSettings settings, bool isDurable, Func <TMessage, Task> handler, IMessageDeserializer <TMessage> deserializer) { var subscriptionSettings = new RabbitMqSubscriptionSettings { ConnectionString = settings.ConnectionString, QueueName = QueueHelper.BuildQueueName(settings.ExchangeName, _env), ExchangeName = settings.ExchangeName, IsDurable = isDurable, }; var rabbitMqSubscriber = new RabbitMqSubscriber <TMessage>(subscriptionSettings, new DefaultErrorHandlingStrategy(_logger, subscriptionSettings)) .SetMessageDeserializer(deserializer) .Subscribe(handler) .SetLogger(_logger) .SetConsole(_consoleWriter); if (!_subscribers.TryAdd(subscriptionSettings, rabbitMqSubscriber)) { throw new InvalidOperationException( $"A subscriber for queue {subscriptionSettings.QueueName} was already initialized"); } rabbitMqSubscriber.Start(); }
public void RegisterDeserializer(ushort messageTypeId, IMessageDeserializer deserializer) { if (deserializer == null) { throw new ArgumentNullException("deserializer"); } _deserializers[messageTypeId] = deserializer; }
public SocketMessageHandler(ICollections collections, ILogger <SocketMessageHandler> logger, IMessageDeserializer deserializer, IEnumerable <IMessageHandler> handlers) { this.collections = collections; this.logger = logger; this.deserializer = deserializer; this.handlers = handlers; }
public static TMessage Deserialize<TMessage>(this IMessageDeserializer<TMessage> deserializer, byte[] obj) where TMessage : class { using (MemoryStream ms = new MemoryStream(obj)) { return deserializer.Deserialize(ms); } }
/// <summary> /// Initialize for queue of the connection string /// </summary> /// <param name="entityName">Queue name</param> /// <param name="connectionStringName">name of the connection string in the setting file</param> /// <param name="deserializer">Object used to deserialize message</param> public BaseMessageReader(string entityName, string connectionStringName, IMessageDeserializer deserializer) : this(entityName, connectionStringName) { if (deserializer is null) { throw new ArgumentNullException(nameof(deserializer)); } MessageDeserializer = deserializer; }
bool TryGetSerializer(ContentType contentType, out IMessageDeserializer deserializer) { if (contentType == null) throw new ArgumentNullException(nameof(contentType)); if (string.IsNullOrWhiteSpace(contentType.MediaType)) throw new ArgumentException("The media type must be specified", nameof(contentType)); return _deserializers.TryGetValue(contentType.MediaType, out deserializer); }
public ForwardingMessageDeserializer(IMessageDeserializer inner) { if (!inner.DotNetType.CanBeCastTo <IForwardsTo <T> >()) { throw new ArgumentOutOfRangeException(nameof(inner), $"Inner reader type {inner.DotNetType.FullName} does not implement {typeof(IForwardsTo<T>).FullName}"); } ContentType = inner.ContentType; _inner = inner; }
/// <inheritdoc /> public SerializedMessageRpcSender( IMessageSerializer <TMessage> serializer, IMessageDeserializer <TResponse> deserializer, IMessageAdapter adapter, ICallContextFactory callContextFactory, string applicationName) : base(adapter, callContextFactory, applicationName) { _serializer = serializer.ThrowIfNull(nameof(serializer)); _deserializer = deserializer.ThrowIfNull(nameof(deserializer)); }
public AsynchronousSocketListener(int port, TimeSpan keepAliveTimeout, IMessageDeserializer messageDeserializer, Action <IMessage, int> messageHandler, IPAddress address) { _connectionIdToTcpConnection = new Dictionary <int, ITcpConnection>(); _port = port; _nextConnectionId = 0; _messageHandler = messageHandler; _messageDeserializer = messageDeserializer; _keepAliveTimeout = keepAliveTimeout; _address = address; }
private static void CreateConsumerService(IBackgroundTaskQueue <MotorCloudEvent <string> >?queue = null, IMessageDeserializer <string>?deserializer = null, IMessageDecoder?decoder = null, IMessageConsumer <string>?consumer = null, bool ignoreEncoding = false) { CreateConsumerService(queue, deserializer, decoder is null ? null : new List <IMessageDecoder> { decoder }, consumer, ignoreEncoding); }
void AddSerializer(IMessageDeserializer deserializer) { if (deserializer == null) { throw new ArgumentNullException(nameof(deserializer)); } string contentType = deserializer.ContentType.MediaType; _deserializers[contentType] = deserializer; }
bool TryGetSerializer(ContentType contentType, out IMessageDeserializer deserializer) { string mediaType = contentType?.MediaType ?? _defaultContentType; if (string.IsNullOrWhiteSpace(mediaType)) { throw new ArgumentException("The media type must be specified", nameof(contentType)); } return(_deserializers.TryGetValue(mediaType, out deserializer)); }
public StatelessServiceBusBatchCommunicationListener(string connectionString, string endpointName, string errorQueueName, IPaymentLogger logger, IContainerScopeFactory scopeFactory, ITelemetry telemetry, IMessageDeserializer messageDeserializer, IApplicationMessageModifier messageModifier) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.scopeFactory = scopeFactory ?? throw new ArgumentNullException(nameof(scopeFactory)); this.telemetry = telemetry ?? throw new ArgumentNullException(nameof(telemetry)); this.messageDeserializer = messageDeserializer ?? throw new ArgumentNullException(nameof(messageDeserializer)); this.messageModifier = messageModifier ?? throw new ArgumentNullException(nameof(messageModifier)); this.connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString)); EndpointName = endpointName ?? throw new ArgumentNullException(nameof(endpointName)); this.errorQueueName = errorQueueName ?? endpointName + "-Errors"; }
void AddSerializer(IMessageDeserializer deserializer) { if (deserializer == null) throw new ArgumentNullException(nameof(deserializer)); string contentType = deserializer.ContentType.MediaType; if (_deserializers.ContainsKey(contentType)) return; _deserializers[contentType] = deserializer; }
/// <summary> /// </summary> /// <param name="writerCloseTimeout">How long should we wait for the writer to finish writing data before closing</param> public MessageStream( IMessageDeserializer <T> deserializer, IMessageSerializer <T> serializer, IDuplexMessageStream duplexMessageStream, MessageStreamOptions options = null ) { this.Deserializer = deserializer; this.Serializer = serializer; this.duplexMessageStream = duplexMessageStream; this.options = options ?? new MessageStreamOptions(); }
public void SetupSerializationTest() { if (_serializerType == typeof(ProtocolBuffersMessageSerializer)) { Serializer = new ProtocolBuffersMessageSerializer(); Deserializer = new ProtocolBuffersMessageDeserializer(); } else { throw new ArgumentException("The serializer type is unknown"); } }
public TypedConsumerService( ILogger <TypedConsumerService <TInput> > logger, IBackgroundTaskQueue <MotorCloudEvent <TInput> > queue, IMessageDeserializer <TInput> deserializer, IMessageConsumer <TInput> consumer) { _logger = logger; _queue = queue; _deserializer = deserializer; _consumer = consumer; _consumer.ConsumeCallbackAsync = SingleMessageConsumeAsync; }
protected BaseTcpConnection(int id, Socket socket, Action <CommunicationException> connectionFailureHandler, IMessageDeserializer messageDeserializer) { Id = id; Socket = socket; MessageDeserializer = messageDeserializer; ConnectionFailureHandler = connectionFailureHandler; MessageProcessed = new ManualResetEvent(true); State = new CommunicationState(); ClientType = ClientType.NonInitialized; }
public ServerMessageStreamReaderTests() { deserializer = A.Fake <IMessageDeserializer>(); stream = A.Fake <NetworkMemoryStream>(o => o.CallsBaseMethods()); preparedMessage = A.Fake <IMessage>(); A.CallTo(() => deserializer.Deserialize(null, 0, 0)) .WithAnyArguments() .Returns(preparedMessage); streamReader = new ServerMessageStreamReader(stream, deserializer); }
public CommunicationServer(IMessageDeserializer messageDeserializer, TimeSpan keepAliveTimeout, int port, IErrorsMessagesFactory errorsMessagesFactory, LoggingMode loggingMode, IPAddress address) { VerboseLogger = new VerboseLogger(LogManager.GetCurrentClassLogger(), loggingMode); _errorsMessagesFactory = errorsMessagesFactory; _socketListener = new AsynchronousSocketListener(port, keepAliveTimeout, messageDeserializer, HandleMessage, address ); _communicationRouter = new CommunicationRouter(); new Thread(() => _socketListener.StartListening(HandleConnectionError)).Start(); }
public ConcurrentMessageStream( IMessageDeserializer <T> deserializer, IMessageSerializer <T> serializer, IDuplexMessageStream duplexMessageStream, UnexpectedCloseDelegateAsync unexpectedCloseDelegate, ConcurrentMessageStreamOptions options = null, RequestResponseKeyResolver <T> rpcKeyResolver = null) : base(deserializer, serializer, duplexMessageStream, options ?? new ConcurrentMessageStreamOptions()) { this.unexpectedCloseDelegateAsync = unexpectedCloseDelegate; this.concurrentOptions = this.options as ConcurrentMessageStreamOptions; this.rpcKeyResolver = rpcKeyResolver; }
public AsynchronousCommunicationClient(IPEndPoint endPoint, TimeSpan keepAliveTimeout, IMessageDeserializer messageDeserializer) { _connectFinalized = new ManualResetEvent(false); _connectDone = new ManualResetEvent(false); _messageDeserializer = messageDeserializer; _ipEndPoint = endPoint; _keepAliveTimeout = keepAliveTimeout == default(TimeSpan) ? Constants.DefaultMaxUnresponsivenessDuration : keepAliveTimeout; _connectedToServer = false; }
public MessageStreamReaderTests() { stream = A.Fake <NetworkMemoryStream>(o => o.CallsBaseMethods()); deserializer = A.Fake <IMessageDeserializer>(); preparedMessage = A.Fake <IMessage>(); A.CallTo(() => deserializer.Deserialize(null, 0, 0)) .WhenArgumentsMatch(FirstMessage) .Returns(preparedMessage); parser = new MessageStreamReader(deserializer, stream); }
public void SetUp() { A.Fake<IConnectionFactory>(); _connection = A.Fake<IConnection>(); _lazyConnection = new Lazy<IConnection>(() => { _connection.Start(); return _connection; }); _session = A.Fake<ISession>(); _consumer = A.Fake<IMessageConsumer>(); _deserializer = A.Fake<IMessageDeserializer<ITestMessage>>(); _observer = A.Fake<IObserver<ITestMessage>>(); _destination = A.Fake<IDestination>(); _acknowledgementMode = AcknowledgementMode.AutoAcknowledge; A.CallTo(() => _connection.CreateSession(A<Apache.NMS.AcknowledgementMode>.Ignored)).Returns(_session); A.CallTo(() => _session.CreateConsumer(_destination)).Returns(_consumer); _source = new MessageSource<ITestMessage>(_lazyConnection, new[] {_deserializer}, _destination, _acknowledgementMode); }
private bool DispatchIncomingMessage(IMessageDeserializer messageDeserializer) { try { var msg = messageDeserializer.DeserializeMessage(); _messageDispatcher.DispatchReceived(new MessageEvent(msg)); } catch (Exception ex) { DispatchError(ex); if (ex.InnerException is IOException) { return true; } if (ex.InnerException is ObjectDisposedException) { return true; } } return false; }
public void RegisterDeserializer(ushort messageTypeId, IMessageDeserializer deserializer) { if (deserializer == null) throw new ArgumentNullException("deserializer"); _deserializers[messageTypeId] = deserializer; }
public ProcessingChannel(IMessageDeserializer deserializer, IHandler<object> handlers) { _deserializer = deserializer; _handlers = handlers; }
public HttpMessageDeserializerProxy(IMessageDeserializer wrapped) { _wrapped = wrapped; }