/// <inheritdoc /> public Task <IMessageEncryptionService> CreateMessageEncryptionService(IConfiguration configuration) { IMessageEncryptionService messageEncryptionService = null; var enabled = configuration != null && configuration.GetValue("enabled", false); if (enabled) { var key = (HexEncodedSecurityKey)configuration.GetValue <string>("key"); if (key == null) { throw new ConfigurationErrorsException("Attribute 'key' is required for AES message encryption service"); } var fallbackKeys = configuration.GetSection("fallbackKeys") .GetChildren() .Select(k => (HexEncodedSecurityKey)k.Value) .ToList(); var aesOptions = new AesMessageEncryptionOptions(key) { FallbackKeys = fallbackKeys }; messageEncryptionService = new AesMessageEncryptionService(aesOptions); } return(Task.FromResult(messageEncryptionService)); }
/// <inheritdoc /> /// <summary> /// Initializes a new <see cref="T:Platibus.MongoDB.MongoDBMessageQueue" /> with the specified values /// </summary> /// <param name="queueName">The name of the queue</param> /// <param name="listener">The object that will be notified when messages are /// added to the queue</param> /// <param name="options">(Optional) Settings that influence how the queue behaves</param> /// <param name="diagnosticService"></param> /// <param name="database">The MongoDB database</param> /// <param name="collectionName">(Optional) The name of the collection in which the /// queued messages should be stored. If omitted, the queue name will be used.</param> /// <param name="securityTokenService"></param> /// <param name="messageEncryptionService">(Optional) The message encryption service used /// to encrypt persistent messages at rest</param> /// <exception cref="T:System.ArgumentNullException"> /// Thrown if <paramref name="database" />, <paramref name="queueName" />, or /// <paramref name="listener" /> are <c>null</c> /// </exception> public MongoDBMessageQueue(QueueName queueName, IQueueListener listener, QueueOptions options, IDiagnosticService diagnosticService, IMongoDatabase database, string collectionName, ISecurityTokenService securityTokenService, IMessageEncryptionService messageEncryptionService) : base(queueName, listener, options, diagnosticService) { if (database == null) { throw new ArgumentNullException(nameof(database)); } if (queueName == null) { throw new ArgumentNullException(nameof(queueName)); } if (listener == null) { throw new ArgumentNullException(nameof(listener)); } _securityTokenService = securityTokenService ?? throw new ArgumentNullException(nameof(securityTokenService)); _messageEncryptionService = messageEncryptionService; var myCollectionName = string.IsNullOrWhiteSpace(collectionName) ? MapToCollectionName(queueName) : collectionName; _queuedMessages = database.GetCollection <QueuedMessageDocument>(myCollectionName); MessageEnqueued += OnMessageEnqueued; MessageAcknowledged += OnMessageAcknowledged; AcknowledgementFailure += OnAcknowledgementFailure; MaximumAttemptsExceeded += OnMaximumAttemptsExceeded; }
/// <inheritdoc /> /// <summary> /// Initializes a new <see cref="T:Platibus.SQL.SQLMessageQueue" /> with the specified values /// </summary> /// <param name="queueName">The name of the queue</param> /// <param name="listener">The object that will be notified when messages are /// added to the queue</param> /// <param name="options">(Optional) Settings that influence how the queue behaves</param> /// <param name="diagnosticService">(Optional) The service through which diagnostic events /// are reported and processed</param> /// <param name="connectionProvider">The database connection provider</param> /// <param name="commandBuilders">A collection of factories capable of /// generating database commands for manipulating queued messages that conform to the SQL /// syntax required by the underlying connection provider</param> /// <param name="securityTokenService">(Optional) The message security token /// service to use to issue and validate security tokens for persisted messages.</param> /// <param name="messageEncryptionService"></param> /// <exception cref="T:System.ArgumentNullException">Thrown if <paramref name="connectionProvider" />, /// <paramref name="commandBuilders" />, <paramref name="queueName" />, or <paramref name="listener" /> /// are <c>null</c></exception> public SQLMessageQueue(QueueName queueName, IQueueListener listener, QueueOptions options, IDiagnosticService diagnosticService, IDbConnectionProvider connectionProvider, IMessageQueueingCommandBuilders commandBuilders, ISecurityTokenService securityTokenService, IMessageEncryptionService messageEncryptionService) : base(queueName, listener, options, diagnosticService) { if (queueName == null) { throw new ArgumentNullException(nameof(queueName)); } if (listener == null) { throw new ArgumentNullException(nameof(listener)); } ConnectionProvider = connectionProvider ?? throw new ArgumentNullException(nameof(connectionProvider)); CommandBuilders = commandBuilders ?? throw new ArgumentNullException(nameof(commandBuilders)); MessageEncryptionService = messageEncryptionService; SecurityTokenService = securityTokenService ?? throw new ArgumentNullException(nameof(securityTokenService)); MessageEnqueued += OnMessageEnqueued; MessageAcknowledged += OnMessageAcknowledged; AcknowledgementFailure += OnAcknowledgementFailure; MaximumAttemptsExceeded += OnMaximumAttemptsExceeded; }
public MongoDBMessageQueueInspector(QueueName queueName, QueueOptions options, IMongoDatabase database, string collectionName, ISecurityTokenService securityTokenService, IMessageEncryptionService messageEncryptionService) : base(queueName, new NoopQueueListener(), options, null, database, collectionName, securityTokenService, messageEncryptionService) { }
public MessageController(SecureMailDbContext context, IMessageEncryptionService hybridEncryptionService, IFileEncryptionService fileEncryptionService) { _secureMailDbContext = context; _messageEncryptionService = hybridEncryptionService; _fileEncryptionService = fileEncryptionService; }
/// <inheritdoc /> /// <summary> /// Initializes a new <see cref="T:Platibus.SQLite.SQLiteMessageQueue" /> /// </summary> /// <param name="queueName">The name of the queue</param> /// <param name="listener">The object that will process messages off of the queue</param> /// <param name="options">(Optional) Options for concurrency and retry limits</param> /// <param name="diagnosticService">(Optional) The service through which diagnostic events /// are reported and processed</param> /// <param name="baseDirectory">The directory in which the SQLite database will be created</param> /// <param name="securityTokenService">(Optional) A service for issuing security tokens /// that can be stored with queued messages to preserve the security context in which /// they were enqueued</param> /// <param name="messageEncryptionService"></param> public SQLiteMessageQueue(QueueName queueName, IQueueListener listener, QueueOptions options, IDiagnosticService diagnosticService, DirectoryInfo baseDirectory, ISecurityTokenService securityTokenService, IMessageEncryptionService messageEncryptionService) : base(queueName, listener, options, diagnosticService, InitConnectionProvider(baseDirectory, queueName, diagnosticService), new SQLiteMessageQueueingCommandBuilders(), securityTokenService, messageEncryptionService) { _cancellationTokenSource = new CancellationTokenSource(); }
/// <summary> /// Initializes a new <see cref="MongoDBMessageQueueingService"/> /// </summary> /// <param name="options">Options governing the behavior of the service</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="options"/> is <c>null</c> /// </exception> public MongoDBMessageQueueingService(MongoDBMessageQueueingOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } _diagnosticService = options.DiagnosticService ?? DiagnosticService.DefaultInstance; _database = options.Database; _collectionNameFactory = options.CollectionNameFactory ?? (_ => DefaultCollectionName); _securityTokenService = options.SecurityTokenService ?? new JwtSecurityTokenService(); _messageEncryptionService = options.MessageEncryptionService; }
/// <summary> /// Initializes a new <see cref="SQLMessageQueueingService"/> with the specified connection /// string settings and dialect /// </summary> /// <param name="options">Options influencing the behavior of this service</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="options"/> /// is <c>null</c></exception> /// <remarks> /// <para>If a SQL dialect is not specified, then one will be selected based on the /// supplied connection string settings</para> /// <para>If a security token service is not specified then a default implementation /// based on unsigned JWTs will be used.</para> /// </remarks> /// <seealso cref="Platibus.Config.Extensibility.IMessageQueueingCommandBuildersProvider"/> public SQLMessageQueueingService(SQLMessageQueueingOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } DiagnosticService = options.DiagnosticService ?? Diagnostics.DiagnosticService.DefaultInstance; ConnectionProvider = options.ConnectionProvider; CommandBuilders = options.CommandBuilders; _securityTokenService = options.SecurityTokenService ?? new JwtSecurityTokenService(); _messageEncryptionService = options.MessageEncryptionService; }
/// <summary> /// Initializes a new <see cref="SQLiteMessageQueueingService"/> /// </summary> /// <param name="options">(Optional) Options that influence the behavior of this service</param> /// <remarks> /// <para>If a base directory is not specified then the base directory will default to a /// directory named <c>platibus\queues</c> beneath the current app domain base /// directory. If the base directory does not exist it will be created.</para> /// <para>If a security token service is not specified then a default implementation based /// on unsigned JWTs will be used.</para> /// </remarks> public SQLiteMessageQueueingService(SQLiteMessageQueueingOptions options) { DiagnosticService = options?.DiagnosticService ?? Diagnostics.DiagnosticService.DefaultInstance; var baseDirectory = options?.BaseDirectory; if (baseDirectory == null) { var appdomainDirectory = AppDomain.CurrentDomain.BaseDirectory; baseDirectory = new DirectoryInfo(Path.Combine(appdomainDirectory, "platibus", "queues")); } _baseDirectory = baseDirectory; _securityTokenService = options?.SecurityTokenService ?? new JwtSecurityTokenService(); _messageEncryptionService = options?.MessageEncryptionService; }
/// <summary> /// Initializes a new <see cref="RabbitMQMessageQueueingService"/> /// </summary> /// <param name="options">Options influencing the configuration and behavior of the service</param> /// <remarks> /// <para>If a security token service is not specified then a default implementation based on /// unsigned JWTs will be used.</para> /// </remarks> public RabbitMQMessageQueueingService(RabbitMQMessageQueueingOptions options) { _uri = options.Uri; _defaultQueueOptions = options.DefaultQueueOptions ?? new QueueOptions(); var myConnectionManager = options.ConnectionManager; if (myConnectionManager == null) { myConnectionManager = new ConnectionManager(); _disposeConnectionManager = true; } _connectionManager = myConnectionManager; _encoding = options.Encoding ?? Encoding.UTF8; _securityTokenService = options.SecurityTokenService ?? new JwtSecurityTokenService(); _diagnosticService = options.DiagnosticService ?? DiagnosticService.DefaultInstance; _messageEncryptionService = options.MessageEncryptionService; }
/// <summary> /// Initializes a new <see cref="FilesystemMessageQueueingService"/> /// </summary> /// <param name="options">Options affecting the behavior of the filesystem message queueing /// service</param> /// <remarks> /// <para>If a base directory is not specified then the base directory will default to a /// directory named <c>platibus\queues</c> beneath the current app domain base /// directory. If the base directory does not exist it will be created in the /// <see cref="Init"/> method.</para> /// <para>If a security token service is not specified then a default implementation based /// on unsigned JWTs will be used.</para> /// </remarks> public FilesystemMessageQueueingService(FilesystemMessageQueueingOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } _diagnosticService = options.DiagnosticService ?? DiagnosticService.DefaultInstance; var myBaseDirectory = options.BaseDirectory; if (myBaseDirectory == null) { var appdomainDirectory = AppDomain.CurrentDomain.BaseDirectory; myBaseDirectory = new DirectoryInfo(Path.Combine(appdomainDirectory, "platibus", "queues")); } _baseDirectory = myBaseDirectory; _securityTokenService = options.SecurityTokenService ?? new JwtSecurityTokenService(); _messageEncryptionService = options.MessageEncryptionService; }
/// <inheritdoc /> public Task <IMessageEncryptionService> CreateMessageEncryptionService(EncryptionElement configuration) { IMessageEncryptionService messageEncryptionService = null; var enabled = configuration.Enabled; if (enabled) { var key = (HexEncodedSecurityKey)configuration.Key; if (key == null) { throw new ConfigurationErrorsException("Attribute 'key' is required for AES message encryption service"); } var fallbackKeys = configuration.FallbackKeys.Select(k => (HexEncodedSecurityKey)k.Key).ToList(); var aesOptions = new AesMessageEncryptionOptions(key) { FallbackKeys = fallbackKeys }; messageEncryptionService = new AesMessageEncryptionService(aesOptions); } return(Task.FromResult(messageEncryptionService)); }
/// <inheritdoc /> /// <summary> /// Initializes a new <see cref="T:Platibus.Filesystem.FilesystemMessageQueue" /> /// </summary> /// <param name="queueName">The name of the queue</param> /// <param name="listener">The listener that will consume messages from the queue</param> /// <param name="options">(Optional) Queueing options</param> /// <param name="diagnosticService">(Optional) The service through which diagnostic events /// are reported and processed</param> /// <param name="directory">The directory into which message files will be persisted</param> /// <param name="securityTokenService">The service used to issue and validate security /// tokens stored with the persisted messages to preserve the security context in which /// the message was received</param> /// <param name="messageEncryptionService"></param> public FilesystemMessageQueue(QueueName queueName, IQueueListener listener, QueueOptions options, IDiagnosticService diagnosticService, DirectoryInfo directory, ISecurityTokenService securityTokenService, IMessageEncryptionService messageEncryptionService) : base(queueName, listener, options, diagnosticService) { if (queueName == null) { throw new ArgumentNullException(nameof(queueName)); } if (listener == null) { throw new ArgumentNullException(nameof(listener)); } _directory = directory ?? throw new ArgumentNullException(nameof(directory)); _deadLetterDirectory = new DirectoryInfo(Path.Combine(directory.FullName, "dead")); _securityTokenService = securityTokenService ?? throw new ArgumentNullException(nameof(securityTokenService)); _messageEncryptionService = messageEncryptionService; MessageEnqueued += OnMessageEnqueued; MessageAcknowledged += OnMessageAcknowledged; MaximumAttemptsExceeded += OnMaximumAttemptsExceeded; }
/// <summary> /// Initializes a new <see cref="RabbitMQQueue"/> /// </summary> /// <param name="connection">The connection to the RabbitMQ server</param> /// <param name="queueName">The name of the queue</param> /// <param name="listener">The listener that will receive new messages off of the queue</param> /// <param name="encoding">(Optional) The encoding to use when converting serialized message /// content to byte streams</param> /// <param name="options">(Optional) Queueing options</param> /// <param name="diagnosticService">(Optional) The service through which diagnostic events /// are reported and processed</param> /// <param name="securityTokenService">(Optional) The message security token /// service to use to issue and validate security tokens for persisted messages.</param> /// <param name="messageEncryptionService"></param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="queueName"/>, /// <paramref name="listener"/>, or <paramref name="connection"/> is <c>null</c></exception> public RabbitMQQueue(IConnection connection, QueueName queueName, IQueueListener listener, Encoding encoding, QueueOptions options, IDiagnosticService diagnosticService, ISecurityTokenService securityTokenService, IMessageEncryptionService messageEncryptionService) { _queueName = queueName ?? throw new ArgumentNullException(nameof(queueName)); _queueExchange = _queueName.GetExchangeName(); _retryQueueName = queueName.GetRetryQueueName(); _retryExchange = _queueName.GetRetryExchangeName(); _deadLetterExchange = _queueName.GetDeadLetterExchangeName(); _listener = listener ?? throw new ArgumentNullException(nameof(listener)); _connection = connection ?? throw new ArgumentNullException(nameof(connection)); _securityTokenService = securityTokenService ?? throw new ArgumentNullException(nameof(securityTokenService)); _encoding = encoding ?? Encoding.UTF8; var myOptions = options ?? new QueueOptions(); _ttl = myOptions.TTL; _autoAcknowledge = myOptions.AutoAcknowledge; _maxAttempts = myOptions.MaxAttempts; _retryDelay = myOptions.RetryDelay; _isDurable = myOptions.IsDurable; var concurrencyLimit = myOptions.ConcurrencyLimit; _cancellationTokenSource = new CancellationTokenSource(); _diagnosticService = diagnosticService ?? DiagnosticService.DefaultInstance; _messageEncryptionService = messageEncryptionService; var consumerTag = _queueName; _consumer = new DurableConsumer(_connection, queueName, HandleDelivery, consumerTag, concurrencyLimit, _autoAcknowledge, _diagnosticService); }
public SQLiteMessageQueueInspector(DirectoryInfo baseDirectory, QueueName queueName, ISecurityTokenService securityTokenService, IMessageEncryptionService messageEncryptionService) : base(queueName, new NoopQueueListener(), null, null, baseDirectory, securityTokenService, messageEncryptionService) { }
public SQLiteMessageQueueingServiceTests(AesEncryptedSQLiteFixture fixture) : base(fixture.DiagnosticService, fixture.MessageQueueingService) { _queueDirectory = fixture.QueueDirectory; _messageEncryptionService = fixture.MessageEncryptionService; }
public LocalDBMessageQueueingServiceTests(AesEncryptedLocalDBFixture fixture) : base(fixture.DiagnosticService, fixture.MessageQueueingService) { MessageEncryptionService = fixture.MessageEncryptionService; }
public SQLMessageQueueInspector(SQLMessageQueueingService messageQueueingService, QueueName queueName, ISecurityTokenService securityTokenService, IMessageEncryptionService messageEncryptionService) : base(queueName, new NoopQueueListener(), null, null, messageQueueingService.ConnectionProvider, messageQueueingService.CommandBuilders, securityTokenService, messageEncryptionService) { }