public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; RabbitMQTriggerAttribute attribute = parameter.GetCustomAttribute <RabbitMQTriggerAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <ITriggerBinding>(null)); } string queueName = Resolve(attribute.QueueName); string hostName = Resolve(attribute.HostName); ushort batchNumber = attribute.BatchNumber; IRabbitMQService service = _provider.GetService(hostName, queueName); return(Task.FromResult <ITriggerBinding>(new RabbitMQTriggerBinding(service, hostName, queueName, batchNumber))); }
public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; RabbitMQTriggerAttribute attribute = parameter.GetCustomAttribute <RabbitMQTriggerAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <ITriggerBinding>(null)); } string connectionString = Utility.ResolveConnectionString(attribute.ConnectionStringSetting, _options.Value.ConnectionString, _configuration); string queueName = Resolve(attribute.QueueName) ?? throw new InvalidOperationException("RabbitMQ queue name is missing"); string hostName = Resolve(attribute.HostName) ?? Constants.LocalHost; string userName = Resolve(attribute.UserNameSetting); string password = Resolve(attribute.PasswordSetting); string deadLetterExchangeName = Resolve(attribute.DeadLetterExchangeName) ?? string.Empty; int port = attribute.Port; if (string.IsNullOrEmpty(connectionString) && !Utility.ValidateUserNamePassword(userName, password, hostName)) { throw new InvalidOperationException("RabbitMQ username and password required if not connecting to localhost"); } // If there's no specified batch number, default to 1 ushort batchNumber = 1; IRabbitMQService service = _provider.GetService(connectionString, hostName, queueName, userName, password, port, deadLetterExchangeName); return(Task.FromResult <ITriggerBinding>(new RabbitMQTriggerBinding(service, hostName, queueName, batchNumber, _logger))); }