Reputation: 488
Is there a convenient way to pass lists as environment variables for Quarkus Configuration except for Comma separation?
MY_FOO=val1,val2,val3
Comma separation works fine (even if it does not look so nice for long lists). But if you have to pass a list of entries where each entry has commas in it, it won't work.
I'm thinking about something similar to Spring Configuration where you can pass list entries with an index as postfix
MY_FOO_0_ = val1
MY_FOO_1_ = val2
MY_FOO_2_ = val3
Upvotes: 0
Views: 3557
Reputation: 1763
If your problem is to pass a comma (,) inside one item of your array, I believe this will help you.
Below I show one example where I pass the items of an array separated by comma (,) and one specific item ( AllowedRemoteAddresses
) of the array that receives commas.
@ConfigProperty(name = "quickfix")
List<String> quickfixSessionSettings;
In the Eclipse Microprofile Config properties file, I just have to put double backslashes before the comma:
quickfix=[default],\
# Sessions,\
[session],\
BeginString=FIX.4.4,\
SenderCompID=EXEC,\
TargetCompID=BANZAI,\
ConnectionType=acceptor,\
StartTime=00:00:00,\
EndTime=00:00:00,\
# Aceptor,\
SocketAcceptPort=9880,\
# Logging,\
ScreenLogShowHeartBeats=Y,\
# Store,\
# FileStorePath=target/data/store,\
JdbcStoreMessagesTableName=messages,\
JdbcStoreSessionsTableName=sessions,\
JdbcLogHeartBeats=Y,\
JdbcLogIncomingTable=messages_log_incoming,\
JdbcLogOutgoingTable=messages_log_outgoing,\
JdbcLogEventTable=event_log,\
JdbcSessionIdDefaultPropertyValue=not_null,\
AllowedRemoteAddresses=localhost\\,127.0.0.1\\,172.0.0.2
List<String>
result inside application:[default]
# Sessions
[session]
BeginString=FIX.4.4
SenderCompID=EXEC
TargetCompID=BANZAI
ConnectionType=acceptor
StartTime=00:00:00
EndTime=00:00:00
# Aceptor
SocketAcceptPort=9880
# Logging
ScreenLogShowHeartBeats=Y
# Store
# FileStorePath=target/data/store
JdbcStoreMessagesTableName=messages
JdbcStoreSessionsTableName=sessions
JdbcLogHeartBeats=Y
JdbcLogIncomingTable=messages_log_incoming
JdbcLogOutgoingTable=messages_log_outgoing
JdbcLogEventTable=event_log
JdbcSessionIdDefaultPropertyValue=not_null
AllowedRemoteAddresses=localhost,127.0.0.1,172.0.0.2
In the Yaml deployment file, I just have to put one backslash before the comma:
environment:
- QUARKUS_DATASOURCE_JDBC_URL=jdbc:postgresql://postgresql-qfj:5432/postgres?currentSchema=exchange
- QUARKUS_DATASOURCE_USERNAME=postgres
- QUARKUS_DATASOURCE_PASSWORD=postgres
- QUICKFIX=[default],
[session],
BeginString=FIX.4.4,
SenderCompID=EXEC,
TargetCompID=BANZAI,
ConnectionType=acceptor,
StartTime=00:00:00,
EndTime=00:00:00,
SocketAcceptPort=9880,
ScreenLogShowHeartBeats=Y,
JdbcStoreMessagesTableName=messages,
JdbcStoreSessionsTableName=sessions,
JdbcLogHeartBeats=Y,
JdbcLogIncomingTable=messages_log_incoming,
JdbcLogOutgoingTable=messages_log_outgoing,
JdbcLogEventTable=event_log,
JdbcSessionIdDefaultPropertyValue=not_null,
AllowedRemoteAddresses=127.0.0.1\,172.0.0.2\,172.0.0.3\,broker-back-end
List<String>
result inside application:[default]
[session]
BeginString=FIX.4.4
SenderCompID=EXEC
TargetCompID=BANZAI
ConnectionType=acceptor
StartTime=00:00:00
EndTime=00:00:00
SocketAcceptPort=9880
ScreenLogShowHeartBeats=Y
JdbcStoreMessagesTableName=messages
JdbcStoreSessionsTableName=sessions
JdbcLogHeartBeats=Y
JdbcLogIncomingTable=messages_log_incoming
JdbcLogOutgoingTable=messages_log_outgoing
JdbcLogEventTable=event_log
JdbcSessionIdDefaultPropertyValue=not_null
AllowedRemoteAddresses=127.0.0.1,172.0.0.2,172.0.0.3,broker-back-end
Upvotes: 0
Reputation: 611
Quarkus uses MicroProfile and SmallRye for this and you can achieve the desired result using indexed properties:
# MicroProfile Config - Collection Values
my.collection=dog,cat,turtle
# SmallRye Config - Indexed Property
my.indexed.collection[0]=dog
my.indexed.collection[1]=cat
my.indexed.collection[2]=turtle
From the documentation:
A call to Config#getValues("my.collection", String.class), will automatically create and convert a List that contains the values dog, cat and turtle. A call to Config#getValues("my.indexed.collection", String.class) returns the exact same result.
Following the rules for conversion in environment variables, you would then pass the environment variables as
MY_INDEXED_COLLECTION_0_=dog
MY_INDEXED_COLLECTION_1_=cat
MY_INDEXED_COLLECTION_2_=turtle
and access these by
ConfigProvider.getConfig().getValue("my.indexed.collection", String.class);
Documentation on indexed properties: https://smallrye.io/smallrye-config/2.11.1/config/indexed-properties/ Documentation on environment variables: https://smallrye.io/smallrye-config/2.11.1/config/environment-variables
Upvotes: 2