public MongoDBMessageQueueingService(ConnectionStringSettings connectionStringSettings,
                                      ISecurityTokenService securityTokenService = null,
                                      string databaseName = null, QueueCollectionNameFactory collectionNameFactory = null)
     : this(new MongoDBMessageQueueingOptions(MongoDBHelper.Connect(connectionStringSettings, databaseName))
 {
     SecurityTokenService = securityTokenService,
     CollectionNameFactory = collectionNameFactory
 })
 {
 }
Example #2
0
        /// <inheritdoc />
        public async Task <IMessageQueueingService> CreateMessageQueueingService(QueueingElement configuration)
        {
            var connectionName = configuration.GetString("connectionName");

            if (string.IsNullOrWhiteSpace(connectionName))
            {
                throw new ConfigurationErrorsException(
                          "Attribute 'connectionName' is required for MongoDB message queueing service");
            }

            QueueCollectionNameFactory collectionNameFactory = null;
            var databaseName       = configuration.GetString("database");
            var collectionName     = configuration.GetString("collection");
            var collectionPerQueue = configuration.GetBool("collectionPerQueue") ?? false;

            if (!string.IsNullOrWhiteSpace(collectionName))
            {
                collectionNameFactory = _ => collectionName;
            }
            else if (collectionPerQueue)
            {
                var collectionPrefix = (configuration.GetString("collectionPrefix") ?? "").Trim();
                collectionNameFactory = queueName => (collectionPrefix + queueName).Trim();
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];

            if (connectionStringSettings == null)
            {
                throw new ConfigurationErrorsException("Connection string settings \"" + connectionName + "\" not found");
            }

            var securityTokenServiceFactory = new SecurityTokenServiceFactory();
            var securitTokenConfig          = configuration.SecurityTokens;
            var securityTokenService        = await securityTokenServiceFactory.InitSecurityTokenService(securitTokenConfig);

            var messageEncrytionServiceFactory = new MessageEncryptionServiceFactory();
            var encryptionSection        = configuration.Encryption;
            var messageEncryptionService = await messageEncrytionServiceFactory.InitMessageEncryptionService(encryptionSection);

            var database        = MongoDBHelper.Connect(connectionStringSettings, databaseName);
            var queueingOptions = new MongoDBMessageQueueingOptions(database)
            {
                CollectionNameFactory    = collectionNameFactory,
                SecurityTokenService     = securityTokenService,
                MessageEncryptionService = messageEncryptionService
            };

            var messageQueueingService = new MongoDBMessageQueueingService(queueingOptions);

            return(messageQueueingService);
        }
Example #3
0
        /// <inheritdoc />
        public Task <ISubscriptionTrackingService> CreateSubscriptionTrackingService(IConfiguration configuration)
        {
            var connectionName = configuration?["connectionName"];

            if (string.IsNullOrWhiteSpace(connectionName))
            {
                throw new ConfigurationErrorsException(
                          "Attribute 'connectionName' is required for MongoDB subscription tracking service");
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];

            if (connectionStringSettings == null)
            {
                throw new ConfigurationErrorsException("Connection string settings \"" + connectionName + "\" not found");
            }

            var databaseName   = configuration?["database"];
            var collectionName = configuration?["collection"];
            var database       = MongoDBHelper.Connect(connectionStringSettings, databaseName);
            var subscriptionTrackingOptions = new MongoDBSubscriptionTrackingOptions(database)
            {
                CollectionName = collectionName
            };
            var subscriptionTrackingService = new MongoDBSubscriptionTrackingService(subscriptionTrackingOptions);

            var multicastSection = configuration?.GetSection("multicast");
            var multicastEnabled = multicastSection?.GetValue("enabled", true) ?? false;

            if (!multicastEnabled)
            {
                return(Task.FromResult <ISubscriptionTrackingService>(subscriptionTrackingService));
            }

            var ipAddress = multicastSection.GetValue("address", IPAddress.Parse("239.255.21.80"));
            var port      = multicastSection.GetValue("port", 52181);
            var multicastTrackingService = new MulticastSubscriptionTrackingService(
                subscriptionTrackingService, ipAddress, port);

            return(Task.FromResult <ISubscriptionTrackingService>(multicastTrackingService));
        }
Example #4
0
        /// <inheritdoc />
        public Task <ISubscriptionTrackingService> CreateSubscriptionTrackingService(SubscriptionTrackingElement configuration)
        {
            var connectionName = configuration.GetString("connectionName");

            if (string.IsNullOrWhiteSpace(connectionName))
            {
                throw new ConfigurationErrorsException(
                          "Attribute 'connectionName' is required for MongoDB subscription tracking service");
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];

            if (connectionStringSettings == null)
            {
                throw new ConfigurationErrorsException("Connection string settings \"" + connectionName + "\" not found");
            }

            var databaseName   = configuration.GetString("database");
            var collectionName = configuration.GetString("collection");
            var database       = MongoDBHelper.Connect(connectionStringSettings, databaseName);
            var subscriptionTrackingOptions = new MongoDBSubscriptionTrackingOptions(database)
            {
                CollectionName = collectionName
            };
            var subscriptionTrackingService = new MongoDBSubscriptionTrackingService(subscriptionTrackingOptions);

            var multicast = configuration.Multicast;

            if (multicast == null || !multicast.Enabled)
            {
                return(Task.FromResult <ISubscriptionTrackingService>(subscriptionTrackingService));
            }

            var multicastTrackingService = new MulticastSubscriptionTrackingService(
                subscriptionTrackingService, multicast.Address, multicast.Port);

            return(Task.FromResult <ISubscriptionTrackingService>(multicastTrackingService));
        }