/// <summary> /// Initializes a new instance of the <see cref="MessageRouter"/> class. /// </summary> /// <param name="messageHandlerFactory">IMessageHandlerFactory to instantiate IMessageHandler.</param> /// <param name="queueRepository">IQueueRepository instance.</param> public MessageRouter(IMessageHandlerFactory messageHandlerFactory, IQueueRepository queueRepository) { this.messageHandlerFactory = messageHandlerFactory; this.queueRepository = queueRepository; this.VisibilityTimeOut = ConfigReader<int>.GetSetting(VisibilityTimeOutAppSettingName); diagnostics = new DiagnosticsProvider(this.GetType()); }
public Router( IMessageHandlerContainer messageHandlerContainer, IMessageHandlerFactory messageHandlerFactory) { this.messageHandlerContainer = messageHandlerContainer; this.messageHandlerFactory = messageHandlerFactory; }
private void ProcessMessageHandlingException(IMessageScope scope, IMessageHandlerFactory handlerFactory, Type messageType, IMessage message, List <Exception> exceptions) { var eventHandler = handlerFactory.GetHandler(scope); try { if (eventHandler == null) { throw new ArgumentNullException($"Registered message handler for message type {messageType.Name} is null!"); } var handlerType = typeof(IMessageHandler <>).MakeGenericType(messageType); var method = handlerType.GetMethod( nameof(IMessageHandler <IMessage> .HandleMessage), new[] { messageType } ); method.Invoke(eventHandler, new object[] { message }); } catch (TargetInvocationException ex) { exceptions.Add(ex.InnerException); } catch (Exception ex) { exceptions.Add(ex); } finally { handlerFactory.ReleaseHandler(scope, eventHandler); } }
public InputMessageChannel(IMessagePipeLine messagePipeLine, IMessageHandlerFactory factory) { Guard.NotNull(factory, nameof(factory)); Guard.NotNull(messagePipeLine, nameof(messagePipeLine)); this.messagePipeLine = messagePipeLine; this.factory = factory; }
public async ValueTask <bool> CallAsync( IMessageScope scope, IMessageHandlerFactory handlerFactory, IMessage message, IRichMessageDescriptor messageDescriptor, List <Exception> exceptions = null, CancellationToken cancellationToken = default) { exceptions = exceptions ?? new List <Exception>(); var handlerDescriptor = handlerFactory.GetHandlerDescriptor(); if (handlerDescriptor.IsAsync) { if (handlerDescriptor.IsRich) { await ProcessRichMessageHandlingExceptionAsync(scope, handlerFactory, handlerDescriptor.MessageType, message, messageDescriptor, exceptions); } else { await ProcessMessageHandlingExceptionAsync(scope, handlerFactory, handlerDescriptor.MessageType, message, exceptions); } } else { if (handlerDescriptor.IsRich) { ProcessRichMessageHandlingException(scope, handlerFactory, handlerDescriptor.MessageType, message, messageDescriptor, exceptions); } else { ProcessMessageHandlingException(scope, handlerFactory, handlerDescriptor.MessageType, message, exceptions); } } return(true); }
public void RegisterRequiredServicesIfMissingApplicationCatalogIsRegisteredWithContainer() { AggregateCatalog _catalog = new AggregateCatalog(new ApplicationCatalog()); AggregateCatalog _newCatalog = DefaultServiceRegistrar.RegisterRequiredServicesIfMissing(_catalog); using (CompositionContainer _container = new CompositionContainer(_newCatalog)) { //Assert.AreEqual<int>(3, _container.Catalog.Parts.Count<ComposablePartDefinition>()); foreach (ComposablePartDefinition _part in _container.Catalog.Parts) { foreach (ImportDefinition _import in _part.ImportDefinitions) { Debug.WriteLine(string.Format("Imported contracts name => '{0}'", _import.ContractName)); } foreach (ExportDefinition _export in _part.ExportDefinitions) { Debug.WriteLine(string.Format("Exported contracts name => '{0}'", _export.ContractName)); } } ITraceSource _exportedValue = _container.GetExportedValue <ITraceSource>(); Assert.IsNotNull(_exportedValue); IInterface _interface = _container.GetExportedValue <IInterface>(); Assert.IsNotNull(_interface); IMessageHandlerFactory _messageHandlerFactory = _container.GetExportedValue <IMessageHandlerFactory>(); Assert.IsNotNull(_messageHandlerFactory); } }
public void TestInitialize() { Ioc.Container = new DependencyInjectionContainer(); _subServiceLocator = Substitute.For <IServiceLocator>(); _subHealthWebRequestClient = Substitute.For <IHealthWebRequestClient>(); _subLocalObjectStore = Substitute.For <ILocalObjectStore>(); _subShellAuthService = Substitute.For <IShellAuthService>(); _subMessageHandlerFactory = Substitute.For <IMessageHandlerFactory>(); _subClientSessionCredentialClient = Substitute.For <IClientSessionCredentialClient>(); _healthVaultConfiguration = new HealthVaultConfiguration { MasterApplicationId = s_masterApplicationId, DefaultHealthVaultUrl = new Uri("https://platform2.healthvault.com/platform/"), DefaultHealthVaultShellUrl = new Uri("https://account.healthvault.com") }; _subServiceLocator.GetInstance <HealthVaultConfiguration>().Returns(_healthVaultConfiguration); _subServiceLocator.GetInstance <IHealthWebRequestClient>().Returns(_subHealthWebRequestClient); _subServiceLocator.GetInstance <SdkTelemetryInformation>().Returns(new SdkTelemetryInformation { FileVersion = "1.0.0.0" }); _subServiceLocator.GetInstance <ICryptographer>().Returns(new Cryptographer()); _subServiceLocator.GetInstance <IHealthServiceResponseParser>().Returns(new HealthServiceResponseParser()); Ioc.Container.RegisterTransient <IPersonClient, PersonClient>(); }
protected override void Given() { _message = JsonTypedMessage.FromMessage(new PrototypeMessage()); _module = new PrototypeModule(); _factory = TypedMessageHandlerFactory.ForMessage(_message); _handler = _factory.GetHandlers(_module).Single(); }
public ProcessingService(Schema schema, IMessageHandlerFactory factory) { _factory = factory; var allSchemaItems = schema.Special.Items.Union(schema.Parts.SelectMany(part => part.Items)).ToDictionary(item => item.Route, item => item); _handlersMethodInfo = CreateMessageHandlersMethodInfo(allSchemaItems); _handlers = CreateMessageHandlers(allSchemaItems); }
public QueueBasedGateway(INodeGatewayAgent nodeGatewayAgent, IMessageHandlerFactory handlerFactory) { _handlerFactory = handlerFactory; _nodeGatewayAgent = nodeGatewayAgent; nodeGatewayAgent.OnMessageReceived += (sender, message) => messageQueue.Enqueue(message);; nodeGatewayAgent.Start(); }
public HelloHomeGateway(INodeGatewayAgent nodeGatewayAgent, IMessageHandlerFactory handlerFactory) { _handlerFactory = handlerFactory; _nodeGatewayAgent = nodeGatewayAgent; nodeGatewayAgent.OnMessageReceived += MessageReceived; nodeGatewayAgent.Start(); }
public CommandExampleConsumer(IMessageHandlerFactory messageHandlerFactory) { if (messageHandlerFactory == null) { throw new ArgumentNullException(nameof(messageHandlerFactory)); } _messageHandlerFactory = messageHandlerFactory; }
public void RegisterHandler <TMessage, THandler>(IMessageHandlerFactory <TMessage, THandler> factory) where THandler : IHandler <TMessage> where TMessage : class, IHaveProcessId, IHaveId { var cfg = new ContainerConfiguration(c => c.Register <THandler>(ctx => factory.Create(ctx.Resolve <IMessageProcessContext>())), c => c.RegisterType <MessageHandleActor <TMessage, THandler> >()); _containerConfigurations.Add(cfg); _maps.Add(factory.CreateRouteMap()); }
public ServiceBusConfigurator MessageHandlerFactory(IMessageHandlerFactory messageHandlerFactory) { Guard.AgainstNull(messageHandlerFactory, "messageHandlerFactory"); configuration.MessageHandlerFactory = messageHandlerFactory; return this; }
public ServiceBusConfigurator MessageHandlerFactory(IMessageHandlerFactory messageHandlerFactory) { Guard.AgainstNull(messageHandlerFactory, "messageHandlerFactory"); configuration.MessageHandlerFactory = messageHandlerFactory; return(this); }
public DefaultConfigurator MessageHandlerFactory(IMessageHandlerFactory messageHandlerFactory) { Guard.AgainstNull(messageHandlerFactory, "messageHandlerFactory"); _configuration.MessageHandlerFactory = messageHandlerFactory; return(this); }
public DefaultConfigurator MessageHandlerFactory(IMessageHandlerFactory messageHandlerFactory) { Guard.AgainstNull(messageHandlerFactory, "messageHandlerFactory"); _configuration.MessageHandlerFactory = messageHandlerFactory; return this; }
public ChatServer(IMessageParser messageParser, IMessageHandlerFactory messageHandlerFactory) { _messageParser = messageParser; _messageHandlerFactory = messageHandlerFactory; _socket = new DumbSocket(); _socket.Start(); _socket.IncomingMessage += OnSocketIncomingMessage; }
public Daemon(IMessageHandlerFactory messageHandlerFactory, IOptions <DaemonOptions> options, ILogger <Daemon> logger) { this.messageHandlerFactory = messageHandlerFactory; this.options = options.Value; this.options.ThrowIfInvalid(); this.logger = logger; }
public WebHttpClientFactory(IMessageHandlerFactory messageHandlerFactory) { _messageHandlerFactory = messageHandlerFactory; HttpClientHandler handler = messageHandlerFactory.Create(); handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; _httpClient = new HttpClient(handler); }
internal static DataManagementSetup CreateDevice(IMessageHandlerFactory messageHandlerFactory, UInt32 dataSetGuid) { AssociationConfigurationId = dataSetGuid; DataManagementSetup _ret = new ConsumerDeviceSimulator(); _ret.ConfigurationFactory = new ConsumerConfigurationFactory(); _ret.BindingFactory = new MVVMSimulatorFactory(); _ret.EncodingFactory = new MyEncodingFactory(); _ret.MessageHandlerFactory = messageHandlerFactory; return _ret; }
public NodeBridge(IMessageChannel messageChannel, IMessageHandlerFactory messageHandlerFactory, ITimeProvider timeProvider, IPerformanceStats performanceStats) { _messageChannel = messageChannel; _messageHandlerFactory = messageHandlerFactory; _timeProvider = timeProvider; _performanceStats = performanceStats; _instanceId = ++instanceCount; Logger.Info($"New NodBridge with instance id {_instanceId}"); }
public void Init() { var catalog = new MessageCatalog(new Collection <MessageEntry> { new MessageEntry(typeof(Message1), typeof(MockMessageHandler <Message1>)), new MessageEntry(typeof(Message2), typeof(MockReusableMessageHandler <Message2>)) }); _factory = new MessageHandlerFactory(catalog); }
public async Task ExecuteAsync(CancellationToken cancellationToken = default) { using (IServiceScope scope = _serviceProvider.CreateScope()) { IServiceProvider serviceProvider = scope.ServiceProvider; IMessageHandlerFactory messageHandlerFactory = serviceProvider.GetRequiredService <IMessageHandlerFactory>(); await messageHandlerFactory.InitialiseAsync(); } }
internal static DataManagementSetup CreateDevice(IMessageHandlerFactory messageHandlerFactory, Guid dataSetGuid) { AssociationConfigurationId = dataSetGuid; DataManagementSetup _ret = new OPCUAServerProducerSimulator(); _ret.ConfigurationFactory = new MyConfigurationFactory(); _ret.BindingFactory = new MyBindingFFactory(); _ret.EncodingFactory = new MyEncodingFactory(); _ret.MessageHandlerFactory = messageHandlerFactory; return(_ret); }
internal static ConsumerDeviceSimulator CreateDevice(IMessageHandlerFactory messageHandlerFactory, UInt32 dataSetGuid) { AssociationConfigurationId = dataSetGuid; ConsumerDeviceSimulator _ret = new ConsumerDeviceSimulator(); _ret.ConfigurationFactory = new ConsumerConfigurationFactory(); _ret.BindingFactory = new MVVMSimulatorFactory(); _ret.EncodingFactory = new MyEncodingFactory(); _ret.MessageHandlerFactory = messageHandlerFactory; return(_ret); }
public HealthVaultSodaConnection( IServiceLocator serviceLocator, ILocalObjectStore localObjectStore, IShellAuthService shellAuthService, IMessageHandlerFactory messageHandlerFactory) : base(serviceLocator) { _localObjectStore = localObjectStore; _shellAuthService = shellAuthService; _messageHandlerFactory = messageHandlerFactory; }
public MessageProcessor( IMessageHandlersCache messageHandlersCache, IMessageTypesCache messageTypesCache, IMessageHandlerFactory messageHandlerFactory, IMessagingLogger messagingLogger ) { _messageHandlersCache = messageHandlersCache; _messageTypesCache = messageTypesCache; _messageHandlerFactory = messageHandlerFactory; _messagingLogger = messagingLogger; }
public void WhenMessageHandlerCreateCalled_ThenFactoryIsInvoked() { var handler = new HttpClientHandler(); _subMessageHandlerFactory.Create().Returns(handler); HealthVaultSodaConnection healthVaultSodaConnection = CreateHealthVaultSodaConnection(); IMessageHandlerFactory factory = healthVaultSodaConnection; var handlerResult = factory.Create(); Assert.AreEqual(handler, handlerResult); }
public async Task ListenWebSocket(int port, string websocketPath, IMessageHandlerFactory factory, IMessageCodec codec) { var connectionListener = this.ServiceProvider.GetRequiredService <IConnectionListener>(); var messageCenter = this.ServiceProvider.GetRequiredService <IMessageCenter>(); var clientFactory = this.ServiceProvider.GetRequiredService <IClientConnectionFactory>(); factory.Codec = codec; clientFactory.Init(); connectionListener.Init(); await connectionListener.BindWebSocketAsync(port, websocketPath, factory).ConfigureAwait(false); }
public async Task BindWebSocketAsync(int port, string websocketPath, IMessageHandlerFactory handlerFactory) { factoryContext[port] = (channel) => { var info = this.channelSessionInfoFactory.NewSessionInfo(handlerFactory); info.ConnectionType = ConnectionType.WebSocket; channel.GetAttribute(ChannelExt.SESSION_INFO).Set(info); var localPort = (channel.LocalAddress as IPEndPoint).Port; info.RemoteAddress = channel.RemoteAddress as IPEndPoint; this.connectionManager.AddConnection(channel); IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast("TimeOut", new IdleStateHandler(this.config.ReadTimeout, this.config.WriteTimeout, this.config.ReadTimeout)); pipeline.AddLast(new HttpServerCodec()); pipeline.AddLast(new HttpObjectAggregator(65536)); pipeline.AddLast(new WebSocketServerCompressionHandler()); pipeline.AddLast(new WebSocketServerProtocolHandler( websocketPath: websocketPath, subprotocols: null, allowExtensions: true, maxFrameSize: 65536, allowMaskMismatch: true, checkStartsWith: false, dropPongFrames: true, enableUtf8Validator: false)); pipeline.AddLast(new WebSocketServerHttpHandler()); pipeline.AddLast(new WebSocketFrameAggregator(65536)); pipeline.AddLast(handlerFactory.NewHandler()); logger.LogInformation("NewWebSocketSession SessionID:{0} IpAddr:{1}, CodecName:{2}", info.SessionID, info.RemoteAddress?.ToString(), handlerFactory.Codec.CodecName); }; var bootstrap = this.MakeBootStrap(); bootstrap.ChildHandler(new ActionChannelInitializer <IChannel>((channel) => { var port = (channel.LocalAddress as IPEndPoint).Port; var factory = this.factoryContext[port]; factory(channel); })); await bootstrap.BindAsync(port); ports.Add(bootstrap); logger.LogInformation("Listen Port:{0}, {1}, Codec:{2}", port, handlerFactory.NewHandler().GetType(), handlerFactory.Codec.GetType()); }
public BackgroundMqCollection(BackgroundMqClient mqClient, IMessageHandlerFactory handlerFactory, int threadCount, int outQMaxSize) { MqClient = mqClient; HandlerFactory = handlerFactory; ThreadCount = threadCount; OutQMaxSize = outQMaxSize; queueMap = new Dictionary <string, BlockingCollection <IMessage> > { { QueueNames <T> .In, new BlockingCollection <IMessage>() }, { QueueNames <T> .Priority, new BlockingCollection <IMessage>() }, { QueueNames <T> .Dlq, new BlockingCollection <IMessage>() }, { QueueNames <T> .Out, new BlockingCollection <IMessage>() }, }; }
public void RegisterRequiredServicesIfMissingAndUDPMessageHandler() { AggregateCatalog _catalog = new AggregateCatalog(new AssemblyCatalog("UAOOI.Networking.UDPMessageHandler.dll"), new AssemblyCatalog("UAOOI.Networking.SimulatorInteroperabilityTest.dll")); AggregateCatalog _newCatalog = DefaultServiceRegistrar.RegisterServices(_catalog); int _disposingCount = 0; using (CompositionContainer _container = new CompositionContainer(_newCatalog)) { IServiceLocator _serviceLocator = new ServiceLocatorAdapter(_container); ServiceLocator.SetLocatorProvider(() => _serviceLocator); Assert.AreEqual <int>(14, _container.Catalog.Parts.Count <ComposablePartDefinition>()); foreach (ComposablePartDefinition _part in _container.Catalog.Parts) { Debug.WriteLine($"New Part: {string.Join(", ", _part.Metadata.Keys.ToArray<string>())}"); foreach (ImportDefinition _import in _part.ImportDefinitions) { Debug.WriteLine(string.Format("Imported contracts name => '{0}'", _import.ContractName)); } foreach (ExportDefinition _export in _part.ExportDefinitions) { Debug.WriteLine(string.Format("Exported contracts name => '{0}'", _export.ContractName)); } } //UDPMessageHandler IMessageHandlerFactory _messageHandlerFactory = _container.GetExportedValue <IMessageHandlerFactory>(); Assert.IsNotNull(_messageHandlerFactory); INetworkingEventSourceProvider _baseEventSource = _messageHandlerFactory as INetworkingEventSourceProvider; Assert.IsNull(_baseEventSource); IEnumerable <INetworkingEventSourceProvider> _diagnosticProviders = _container.GetExportedValues <INetworkingEventSourceProvider>(); Assert.AreEqual <int>(4, _diagnosticProviders.Count <INetworkingEventSourceProvider>()); // DataLogger EventSourceBootstrapper _eventSourceBootstrapper = _container.GetExportedValue <EventSourceBootstrapper>(); LoggerManagementSetup _logger = _container.GetExportedValue <LoggerManagementSetup>(); _logger.DisposeCheck(x => _disposingCount++); Assert.IsNotNull(_logger.BindingFactory); Assert.IsNotNull(_logger.ConfigurationFactory); Assert.IsNotNull(_logger.EncodingFactory); Assert.IsNotNull(_logger.MessageHandlerFactory); SimulatorDataManagementSetup _simulator = _container.GetExportedValue <IDataRepositoryStartup>() as SimulatorDataManagementSetup; Assert.IsNotNull(_simulator); Assert.IsNotNull(_simulator.BindingFactory); Assert.IsNotNull(_simulator.ConfigurationFactory); Assert.IsNotNull(_simulator.EncodingFactory); Assert.IsNotNull(_simulator.MessageHandlerFactory); _simulator.DisposeCheck(x => _disposingCount++); Assert.AreEqual <int>(0, _disposingCount); } Assert.AreEqual <int>(2, _disposingCount); }
public HandlerRegistration(IMessageHandlerFactory messageHandlerFactory, THandlerConfiguration configuration) { if (messageHandlerFactory == null) { throw new ArgumentNullException("messageHandlerFactory"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } this.MessageHandlerFactory = messageHandlerFactory; this.Configuration = configuration; }
public PeekMessagePump(AzureServiceBusSettings settings, IMessageHandlerFactory messageHandlerFactory, ServiceBusConnection connection, MessagingFactory messagingFactory, string inputQueue) { _settings = settings; _messageHandlerFactory = messageHandlerFactory; _messagingFactory = messagingFactory; // The RetryPolicy.Default supplied to the receiver uses an exponential backoff // for transient failures. _messageReceiver = new MessageReceiver(connection, inputQueue, ReceiveMode.PeekLock, RetryPolicy.Default); _messageReceiver.PrefetchCount = _settings.PrefetchCount; }
public async Task Listen(int port, IMessageHandlerFactory factory, IMessageCodec codec) { var connectionListener = this.ServiceProvider.GetRequiredService <IConnectionListener>(); var messageCenter = this.ServiceProvider.GetRequiredService <IMessageCenter>(); var clientFactory = this.ServiceProvider.GetRequiredService <IClientConnectionFactory>(); var clientConnectionPool = this.serviceProvider.GetRequiredService <ClientConnectionPool>(); factory.Codec = codec; clientFactory.Init(); connectionListener.Init(); await connectionListener.BindAsync(port, factory).ConfigureAwait(false); clientConnectionPool.MessageHandlerFactory = factory; }
public UaooiMessageBus( IConfigurationFactory configurationFactory, IEncodingFactory encodingFactory, IBindingFactory subscriptionFactory, IMessageHandlerFactory messageHandlerFactory, ILogger logger) { ConfigurationFactory = configurationFactory ?? throw new ComponentNotInitialisedException(nameof(configurationFactory)); EncodingFactory = encodingFactory ?? throw new ComponentNotInitialisedException(nameof(encodingFactory)); BindingFactory = subscriptionFactory ?? throw new ComponentNotInitialisedException(nameof(subscriptionFactory)); MessageHandlerFactory = messageHandlerFactory ?? throw new ComponentNotInitialisedException(nameof(messageHandlerFactory)); _logger = logger; }
public MessagesProcessor(IMessageHandlerFactory messageHandlerFactory) { this.messageHandlerFactory = messageHandlerFactory; }
/// <summary> /// Reuturns the message Router instance. /// </summary> /// <param name="nullMessageHandler">Indicates if the handler has to be returned or not.</param> /// <returns>MessaeRouter instance.</returns> private MessageRouter GetMessageRouter(bool nullMessageHandler) { this.processedMessage = new List<BaseMessage>(); this.fileServiceFactory = new StubIFileServiceFactory(); this.repositoryService = new StubIRepositoryService(); this.blobRepository = new StubIBlobDataRepository(); IMessageHandler messageHandler = null; if (!nullMessageHandler) { messageHandler = new StubIMessageHandler() { ProcessMessageBaseMessage = (message) => { this.processedMessage.Add(message); } }; } this.messageHandlerFactory = new StubIMessageHandlerFactory { GetMessageHandlerMessageHandlerEnum = (handler) => { return messageHandler; } }; this.queueRepository = new StubIQueueRepository() { GetQueuedMessagesInt32Int32 = (noofmessages, visibilityTimeout) => { return this.messages; } }; MessageRouter messageRouter = new MessageRouter(this.messageHandlerFactory, this.queueRepository); return messageRouter; }
public EventDispatcher(IMessageHandlerFactory factory) { _factory = factory; }
internal static DataManagementSetup CreateDevice(IMessageHandlerFactory messageHandlerFactory, Guid dataSetGuid) { AssociationConfigurationId = dataSetGuid; DataManagementSetup _ret = new OPCUAServerProducerSimulator(); _ret.ConfigurationFactory = new MyConfigurationFactory(); _ret.BindingFactory = new MyBindingFFactory(); _ret.EncodingFactory = new MyEncodingFactory(); _ret.MessageHandlerFactory = messageHandlerFactory; return _ret; }
public MessageDispatcher(IMessageHandlerFactory messageHandlerFactory) { _messageHandlerFactory = messageHandlerFactory; }