/// <summary> /// Creates an initializes a <see cref="IMessageQueueingService"/> /// based on the provided <paramref name="configuration"/> /// </summary> /// <param name="configuration">The journaling configuration /// element</param> /// <returns>Returns a task whose result is an initialized /// <see cref="IMessageQueueingService"/></returns> public async Task <IMessageQueueingService> CreateMessageQueueingService(IConfiguration configuration) { var securityTokenServiceFactory = new SecurityTokenServiceFactory(); var securityTokensSection = configuration?.GetSection("securityTokens"); var securityTokenService = await securityTokenServiceFactory.InitSecurityTokenService(securityTokensSection); var defaultUri = new Uri("amqp://localhost:5672"); var uri = configuration?.GetValue("uri", defaultUri) ?? defaultUri; var encodingName = configuration?["encoding"]; if (string.IsNullOrWhiteSpace(encodingName)) { encodingName = "UTF-8"; } var encoding = ParseEncoding(encodingName); var messageEncryptionServiceFactory = new MessageEncryptionServiceFactory(); var messageEncryptionConfig = configuration?.GetSection("encryption"); var messageEncryptionService = await messageEncryptionServiceFactory.InitMessageEncryptionService(messageEncryptionConfig); var queueingOptions = new RabbitMQMessageQueueingOptions(uri) { Encoding = encoding, SecurityTokenService = securityTokenService, MessageEncryptionService = messageEncryptionService }; var messageQueueingService = new RabbitMQMessageQueueingService(queueingOptions); return(messageQueueingService); }
/// <summary> /// Creates an initializes a <see cref="IMessageQueueingService"/> /// based on the provided <paramref name="configuration"/> /// </summary> /// <param name="configuration">The journaling configuration /// element</param> /// <returns>Returns a task whose result is an initialized /// <see cref="IMessageQueueingService"/></returns> public async Task <IMessageQueueingService> CreateMessageQueueingService(QueueingElement configuration) { var securityTokenServiceFactory = new SecurityTokenServiceFactory(); var securitTokenConfig = configuration.SecurityTokens; var securityTokenService = await securityTokenServiceFactory.InitSecurityTokenService(securitTokenConfig); var uri = configuration.GetUri("uri") ?? new Uri("amqp://localhost:5672"); var encodingName = configuration.GetString("encoding"); if (string.IsNullOrWhiteSpace(encodingName)) { encodingName = "UTF-8"; } var encoding = ParseEncoding(encodingName); var messageEncryptionServiceFactory = new MessageEncryptionServiceFactory(); var messageEncryptionConfig = configuration.Encryption; var messageEncryptionService = await messageEncryptionServiceFactory.InitMessageEncryptionService(messageEncryptionConfig); var queueingOptions = new RabbitMQMessageQueueingOptions(uri) { Encoding = encoding, SecurityTokenService = securityTokenService, MessageEncryptionService = messageEncryptionService }; var messageQueueingService = new RabbitMQMessageQueueingService(queueingOptions); return(messageQueueingService); }
private RabbitMQHost(IRabbitMQHostConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var diagnosticService = configuration.DiagnosticService; var baseUri = configuration.BaseUri.WithoutTrailingSlash(); _connectionManager = new ConnectionManager(); var encoding = configuration.Encoding ?? Encoding.UTF8; var defaultQueueOptions = new QueueOptions { AutoAcknowledge = configuration.AutoAcknowledge, MaxAttempts = configuration.MaxAttempts, ConcurrencyLimit = configuration.ConcurrencyLimit, RetryDelay = configuration.RetryDelay, IsDurable = configuration.IsDurable }; var securityTokenService = configuration.SecurityTokenService ?? new JwtSecurityTokenService(); _messageJournal = configuration.MessageJournal; var queueingOptions = new RabbitMQMessageQueueingOptions(baseUri) { ConnectionManager = _connectionManager, DefaultQueueOptions = defaultQueueOptions, DiagnosticService = diagnosticService, Encoding = encoding, SecurityTokenService = securityTokenService }; _messageQueueingService = new RabbitMQMessageQueueingService(queueingOptions); var transportServiceOptions = new RabbitMQTransportServiceOptions(baseUri, _connectionManager) { DiagnosticService = configuration.DiagnosticService, MessageJournal = configuration.MessageJournal, SecurityTokenService = configuration.SecurityTokenService, Encoding = configuration.Encoding, DefaultQueueOptions = defaultQueueOptions, Topics = configuration.Topics }; _transportService = new RabbitMQTransportService(transportServiceOptions); Bus = new Bus(configuration, configuration.BaseUri, _transportService, _messageQueueingService); }
/// <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; }