/// <summary>
 /// Constructor
 /// </summary>
 /// <param name="logger">Logger</param>
 /// <param name="options">Options</param>
 public ConnectionPool(ILogger <ConnectionPool> logger, ActiveMQOptions options)
 {
     _logger              = logger;
     _maxSize             = defaultPoolSize;
     _pool                = new ConcurrentQueue <ISession>();
     _connectionActivator = GetConnectionActivator(options);
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="groupId">Group Id</param>
        /// <param name="connectionPool">Connection pool for session creation</param>
        /// <param name="options">Options</param>
        public ActiveMQConsumerClient(string groupId, IConnectionPool connectionPool, ActiveMQOptions options)
        {
            _groupId         = groupId;
            _ActiveMQOptions = options;

            _session = connectionPool.GetConnection().CreateSession(AcknowledgementMode.Transactional);
        }
        /// <summary>
        /// Add services of ActiveMQ for CAP
        /// </summary>
        /// <param name="services"></param>
        public void AddServices(IServiceCollection services)
        {
            services.AddSingleton <CapMessageQueueMakerService>();

            var options = new ActiveMQOptions();

            _configure?.Invoke(options);
            services.AddSingleton(options);

            services.AddSingleton <IConsumerClientFactory, ActiveMQConsumerClientFactory>();
            services.AddSingleton <IConnectionPool, ConnectionPool>();
            services.AddSingleton <IPublishExecutor, ActiveMQPublishMessageSender>();
            services.AddSingleton <IPublishMessageSender, ActiveMQPublishMessageSender>();
        }
        /// <summary>
        /// Get IConnection instance activator with options
        /// </summary>
        /// <param name="options">Options</param>
        /// <returns>IConnection instance activator</returns>
        private static Func <Connection> GetConnectionActivator(ActiveMQOptions options)
        {
            var protocol   = options.UseSsl ? "ssl" : "tcp";
            var connectUri = new Uri($"activemq:{protocol}://{options.HostName}:{options.Port}");
            var factory    = new NMSConnectionFactory(connectUri);

            options.ConnectionFactoryOptions?.Invoke(factory);
            return(() =>
            {
                var conn = (Connection)factory.CreateConnection(options.UserName, options.Password);
                conn.Start();
                return conn;
            });
        }
示例#5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ActiveMQOptions">Options</param>
 /// <param name="connectionPool">Connection pool</param>
 public ActiveMQConsumerClientFactory(ActiveMQOptions ActiveMQOptions, IConnectionPool connectionPool)
 {
     _ActiveMQOptions = ActiveMQOptions;
     _connectionPool  = connectionPool;
 }