/// <summary>
        /// Applies configurations on connector
        /// </summary>
        private void ConfigureConnector(TmqStickyConnector connector)
        {
            connector.AutoSubscribe = _autoSubscribe;
            connector.DisconnectionOnAutoJoinFailure = _disconnectOnSubscribeFailure;
            if (_contentSerializer != null)
            {
                connector.ContentSerializer = _contentSerializer;
            }

            foreach (string host in _hosts)
            {
                connector.AddHost(host);
            }

            if (_connected != null)
            {
                connector.Connected += new ConnectionEventMapper(connector, _connected).Action;
            }

            if (_disconnected != null)
            {
                connector.Disconnected += new ConnectionEventMapper(connector, _disconnected).Action;
            }

            if (_error != null)
            {
                connector.ExceptionThrown += new ExceptionEventMapper(connector, _error).Action;
            }
        }
Пример #2
0
        /// <summary>
        /// Uses twino bus and connects to the server
        /// </summary>
        public static IServiceProvider UseTwinoBus <TIdentifier>(this IServiceProvider provider)
        {
            MicrosoftDependencyConsumerFactory.Provider = provider;
            TmqStickyConnector <TIdentifier> connector = provider.GetService <TmqStickyConnector <TIdentifier> >();

            connector.Run();
            return(provider);
        }
 /// <summary>
 /// Releases all resources
 /// </summary>
 internal void Dispose()
 {
     _connector    = null;
     _connected    = null;
     _disconnected = null;
     _error        = null;
     _enhance      = null;
     _hosts.Clear();
     _assembyConsumers.Clear();
     _individualConsumers.Clear();
 }
        /// <summary>
        /// Registers all consumers.
        /// This method is called if implementation is done without ioc container.
        /// </summary>
        private void RegisterConsumers(TmqStickyConnector connector)
        {
            foreach (Tuple <ImplementationType, Type> pair in _assembyConsumers)
            {
                connector.Observer.RegisterAssemblyConsumers(pair.Item2);
            }

            foreach (Tuple <ImplementationType, Type> pair in _individualConsumers)
            {
                connector.Observer.RegisterConsumer(pair.Item2);
            }
        }
        /// <summary>
        /// Builds new TmqStickyConnector with defined properties
        /// </summary>
        public TmqStickyConnector <TIdentifier> Build <TIdentifier>()
        {
            if (_connector != null)
            {
                return((TmqStickyConnector <TIdentifier>)_connector);
            }

            _connector = new TmqStickyConnector <TIdentifier>(_reconnectInterval, new ConnectorInstanceCreator(_id, _name, _type, _token, _enhance).CreateInstance);
            ConfigureConnector(_connector);

            return((TmqStickyConnector <TIdentifier>)_connector);
        }
        /// <summary>
        /// Builds new TmqStickyConnector with defined properties.
        /// </summary>
        public TmqStickyConnector Build()
        {
            if (_connector != null)
            {
                return(_connector);
            }

            _connector = new TmqStickyConnector(_reconnectInterval, new ConnectorInstanceCreator(_id, _name, _type, _token, _enhance).CreateInstance);
            ConfigureConnector(_connector);
            if (_serviceContainer == null)
            {
                RegisterConsumers(_connector);
            }

            return(_connector);
        }
Пример #7
0
        /// <summary>
        /// Adds Twino connector with configuration
        /// </summary>
        public static IServiceCollection AddTwinoBus(this IServiceCollection services, Action <TwinoConnectorBuilder> config)
        {
            TwinoConnectorBuilder builder = new TwinoConnectorBuilder(services);

            config(builder);

            TmqStickyConnector connector = builder.Build();

            AddConsumersMicrosoftDI(services, connector, builder);
            services.AddSingleton(connector);
            services.AddSingleton(connector.Bus);
            services.AddSingleton(connector.Bus.Direct);
            services.AddSingleton(connector.Bus.Queue);
            services.AddSingleton(connector.Bus.Route);

            return(services);
        }
Пример #8
0
        private static void AddConsumersMicrosoftDI(IServiceCollection services, TmqStickyConnector connector, TwinoConnectorBuilder builder)
        {
            foreach (Tuple <ImplementationType, Type> pair in builder.AssembyConsumers)
            {
                IEnumerable <Type> types = connector.Observer
                                           .RegisterAssemblyConsumers(() => new MicrosoftDependencyConsumerFactory(pair.Item1.ToLifeTime()),
                                                                      pair.Item2);

                foreach (Type type in types)
                {
                    AddConsumerIntoCollection(services, pair.Item1, type);
                }
            }

            foreach (Tuple <ImplementationType, Type> pair in builder.IndividualConsumers)
            {
                connector.Observer.RegisterConsumer(pair.Item2, () => new MicrosoftDependencyConsumerFactory(pair.Item1.ToLifeTime()));
                AddConsumerIntoCollection(services, pair.Item1, pair.Item2);
            }
        }
Пример #9
0
        /// <summary>
        /// Adds Twino connector with configuration
        /// </summary>
        public static IServiceCollection AddTwinoBus <TIdentifier>(this IServiceCollection services, Action <TwinoConnectorBuilder> config)
        {
            TwinoConnectorBuilder builder = new TwinoConnectorBuilder(services);

            config(builder);

            TmqStickyConnector <TIdentifier> connector = builder.Build <TIdentifier>();

            AddConsumersMicrosoftDI(services, connector, builder);
            services.AddSingleton(connector);

            TwinoBus <TIdentifier> bus = (TwinoBus <TIdentifier>)connector.Bus;

            services.AddSingleton <ITwinoBus <TIdentifier> >(bus);
            services.AddSingleton <ITwinoDirectBus <TIdentifier> >((TwinoDirectBus <TIdentifier>)bus.Direct);
            services.AddSingleton <ITwinoQueueBus <TIdentifier> >((TwinoQueueBus <TIdentifier>)bus.Queue);
            services.AddSingleton <ITwinoRouteBus <TIdentifier> >((TwinoRouteBus <TIdentifier>)bus.Route);

            return(services);
        }
Пример #10
0
        private static void AddConsumersTwino(ITwinoServiceCollection services, TmqStickyConnector connector, TwinoConnectorBuilder builder)
        {
            foreach (Tuple <ImplementationType, Type> pair in builder.AssembyConsumers)
            {
                IEnumerable <Type> types = connector.Observer
                                           .RegisterAssemblyConsumers(() => new TwinoIocConsumerFactory((IServiceContainer)services, pair.Item1),
                                                                      pair.Item2);

                foreach (Type type in types)
                {
                    AddConsumerIntoContainer(services, pair.Item1, type);
                }
            }

            foreach (Tuple <ImplementationType, Type> pair in builder.IndividualConsumers)
            {
                connector.Observer.RegisterConsumer(pair.Item2,
                                                    () => new TwinoIocConsumerFactory((IServiceContainer)services, pair.Item1));
                AddConsumerIntoContainer(services, pair.Item1, pair.Item2);
            }
        }
 /// <summary>
 /// Creates new connection event wrapper
 /// </summary>
 public ExceptionEventMapper(TmqStickyConnector connector, Action <Exception> action)
 {
     _connector = connector;
     _action    = action;
 }
 /// <summary>
 /// Creates new connection event wrapper
 /// </summary>
 public ConnectionEventMapper(TmqStickyConnector connector, Action <TmqStickyConnector> action)
 {
     _connector = connector;
     _action    = action;
 }