public async Task Should_get_all_bindings_for_which_the_exchange_is_the_source() { var sourceXchange = await CreateExchange("sourceXcg").ConfigureAwait(false); var destionationXchange = await CreateExchange("destinationXcg").ConfigureAwait(false); var bindingInfo = new BindingInfo("#"); await managementClient.CreateBindingAsync(sourceXchange, destionationXchange, bindingInfo).ConfigureAwait(false); Assert.NotEmpty((await managementClient.GetBindingsWithSourceAsync(sourceXchange).ConfigureAwait(false)).ToList()); }
/// <summary> /// Create a binding between an exchange and an exchange /// </summary> /// <param name="source"></param> /// <param name="sourceExchange">the source exchange</param> /// <param name="destinationExchange">the destination exchange</param> /// <param name="bindingInfo">properties of the binding</param> /// <param name="cancellationToken"></param> public static void CreateBinding( [NotNull] this IManagementClient source, [NotNull] Exchange sourceExchange, [NotNull] Exchange destinationExchange, [NotNull] BindingInfo bindingInfo, CancellationToken cancellationToken = default ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } source.CreateBindingAsync(sourceExchange, destinationExchange, bindingInfo, cancellationToken) .GetAwaiter() .GetResult(); }
public async Task Should_create_binding() { var vhost = await managementClient.GetVhostAsync(vhostName).ConfigureAwait(false); var queue = await managementClient.GetQueueAsync(testQueue, vhost).ConfigureAwait(false); var exchange = await managementClient.GetExchangeAsync(testExchange, vhost).ConfigureAwait(false); var bindingInfo = new BindingInfo(testQueue); await managementClient.CreateBindingAsync(exchange, queue, bindingInfo).ConfigureAwait(false); }
public async Task <bool> CreateUserAsync(string username, string password) { var vhost = await _managementClient.GetVhostAsync("/"); if ((await _managementClient.GetUsersAsync()).Any(u => string.Equals(u.Name, username, StringComparison.InvariantCultureIgnoreCase))) { _logger.LogInformation($"User '{username}' already exists"); return(false); } var userInfo = new UserInfo(username, password); var rabbitUser = await _managementClient.CreateUserAsync(userInfo); _logger.LogInformation($"RabbitMQ user '{username}' created"); var logExchangeName = $"logs.{username}"; var exchangeInfo = new ExchangeInfo(logExchangeName, ExchangeType.Fanout); await _managementClient.CreateExchangeAsync(exchangeInfo, vhost); _logger.LogInformation($"RabbitMQ exchange for user '{username}' created"); var logQueueName = (await _bus.Advanced.QueueDeclareAsync("", maxLength: 1, maxLengthBytes: 4096)).Name; var logExchange = await _managementClient.GetExchangeAsync(logExchangeName, vhost); var logQueue = await _managementClient.GetQueueAsync(logQueueName, vhost); await _managementClient.CreateBindingAsync(logExchange, logQueue, new BindingInfo("")); var permissionInfo = new PermissionInfo(rabbitUser, vhost) .DenyAllConfigure() .SetRead("^amq\\.") .SetWrite("^logs\\."); await _managementClient.CreatePermissionAsync(permissionInfo); _logger.LogInformation($"RabbitMQ permissions for user '{username}' set"); var errorExchange = await _managementClient.GetExchangeAsync("errors", vhost); var errorQueueName = (await _bus.Advanced.QueueDeclareAsync("")).Name; _logger.LogInformation($"RabbitMQ error queue for user '{username}' created"); var errorQueue = await _managementClient.GetQueueAsync(errorQueueName, vhost); await _managementClient.CreateBindingAsync(errorExchange, errorQueue, new BindingInfo(username)); _logger.LogInformation($"RabbitMQ error queue for user '{username}' bound to error exchange"); await _elasticsearchClient.CreateUserAsync(username, password); _logger.LogInformation($"ElasticSearch user '{username}' created"); await _elasticsearchClient.CreateIndexAsync(username); _logger.LogInformation($"ElasticSearch index for '{username}' created"); var salt = CryptoUtils.GenerateSalt(); var passwordHash = CryptoUtils.ComputeHash(salt, password); var user = new Deer.Models.User { Username = username, Salt = salt, PasswordHash = passwordHash, LogIndexName = username, LogExchangeName = logExchangeName, LogQueueName = logQueueName, ErrorQueueName = errorQueueName }; await _userRepository.CreateAsync(user); _logger.LogInformation($"UserInfo for user '{username}' saved to MongoDB"); await _logConsumerService.AddConsumerForUserAsync(username); _logger.LogInformation($"Added log consumer for user '{username}'"); return(true); }