在docker compose中将env变量设置为字符串数组
我想从docker-compose.override文件中读取队列名称。为此,我制作了字符串数组 并定义如下在docker compose中将env变量设置为字符串数组,docker,docker-compose,Docker,Docker Compose,我想从docker-compose.override文件中读取队列名称。为此,我制作了字符串数组 并定义如下 环境: - RabbitMQOptions__ConnectionString=-rabbitmq - RabbitMQOptions__BrokerName=event_demo - RabbitMQOptions__QueueName=["sampleQueue", "daemonQueue"] Docker compose文件构建得很好。但是我无法从数组中获取任何值。是否有
环境:
- RabbitMQOptions__ConnectionString=-rabbitmq
- RabbitMQOptions__BrokerName=event_demo
- RabbitMQOptions__QueueName=["sampleQueue", "daemonQueue"]
Docker compose文件构建得很好。但是我无法从数组中获取任何值。是否有其他方法来设置此env变量
我正在通过Startup.cs文件注入docker compose文件中的值
services.AddSingleton<IEventBus, RabbitMQEventBus>(sp =>
{
var rabbitMQPersistentConnection = sp.GetRequiredService<IRabbitMQPersistentConnection>();
var logger = sp.GetRequiredService<ILogger<RabbitMQEventBus>>();
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionManager>();
var options = sp.GetRequiredService<IOptionsMonitor<RabbitMQOptions>>();
return new RabbitMQEventBus(options.CurrentValue, eventBusSubcriptionsManager, rabbitMQPersistentConnection, logger, services);
});
环境变量总是简单的字符串,而不是数组或其他类型。您是否也控制使用此值的代码,如果是,是否可以将其包括在问题中?环境变量始终是简单的字符串,而不是数组或其他类型。您是否也控制使用此值的代码,如果是,是否可以将其包含在问题中?
public RabbitMQEventBus(
RabbitMQOptions options,
IEventBusSubscriptionManager subscriptionManager,
IRabbitMQPersistentConnection persistentConnection,
ILogger<RabbitMQEventBus> logger,
IServiceCollection services
)
{
_persistentConnection = persistentConnection;
_subsManager = subscriptionManager;
_options = options;
_queueName = _options.QueueName[0];
_consumerChannel = CreateConsumerChannel();
_subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
_logger = logger;
_services = services;
BROKER_NAME = _options.BrokerName;
}
public class RabbitMQOptions
{
public string ConnectionString { get; set; }
public string BrokerName { get; set; }
public string[] QueueName { get; set; }
}