feat(event-notifier): improve environment variable handling

- Fix deserialization error when parsing config from environment variables
- Add proper array format support for adapters configuration
- Update environment variable examples with correct format
- Improve documentation for configuration loading
- Implement helper functions for environment variable validation

This change fixes the "invalid type: map, expected a sequence" error
by ensuring proper formatting of array-type fields in environment variables.
This commit is contained in:
houseme
2025-04-22 20:31:38 +08:00
parent 15b6a426fb
commit e4453adf82
18 changed files with 345 additions and 261 deletions
+25 -24
View File
@@ -1,27 +1,28 @@
# basic configuration
EVENT_NOTIF_STORE_PATH=/var/log/event-notification
EVENT_NOTIF_CHANNEL_CAPACITY=5000
# ===== global configuration =====
NOTIFIER__STORE_PATH=/var/log/event-notification
NOTIFIER__CHANNEL_CAPACITY=5000
# webhook adapter configuration
EVENT_NOTIF_ADAPTERS__0__TYPE=Webhook
EVENT_NOTIF_ADAPTERS__0__ENDPOINT=https://api.example.com/webhook
EVENT_NOTIF_ADAPTERS__0__AUTH_TOKEN=your-secret-token
EVENT_NOTIF_ADAPTERS__0__MAX_RETRIES=3
EVENT_NOTIF_ADAPTERS__0__TIMEOUT=5000
# ===== adapter configuration array format =====
# webhook adapter index 0
NOTIFIER__ADAPTERS_0__type=Webhook
NOTIFIER__ADAPTERS_0__endpoint=http://127.0.0.1:3000/webhook
NOTIFIER__ADAPTERS_0__auth_token=your-auth-token
NOTIFIER__ADAPTERS_0__max_retries=3
NOTIFIER__ADAPTERS_0__timeout=50
NOTIFIER__ADAPTERS_0__custom_headers__x_custom_server=server-value
NOTIFIER__ADAPTERS_0__custom_headers__x_custom_client=client-value
# kafka adapter configuration
EVENT_NOTIF_ADAPTERS__1__TYPE=Kafka
EVENT_NOTIF_ADAPTERS__1__BROKERS=localhost:9092
EVENT_NOTIF_ADAPTERS__1__TOPIC=notifications
EVENT_NOTIF_ADAPTERS__1__MAX_RETRIES=3
EVENT_NOTIF_ADAPTERS__1__TIMEOUT=5000
# kafka adapter index 1
NOTIFIER__ADAPTERS_1__type=Kafka
NOTIFIER__ADAPTERS_1__brokers=localhost:9092
NOTIFIER__ADAPTERS_1__topic=notifications
NOTIFIER__ADAPTERS_1__max_retries=3
NOTIFIER__ADAPTERS_1__timeout=60
# mqtt adapter configuration
EVENT_NOTIF_ADAPTERS__2__TYPE=Mqtt
EVENT_NOTIF_ADAPTERS__2__BROKER=mqtt.example.com
EVENT_NOTIF_ADAPTERS__2__PORT=1883
EVENT_NOTIF_ADAPTERS__2__CLIENT_ID=event-notifier
EVENT_NOTIF_ADAPTERS__2__TOPIC=events
EVENT_NOTIF_ADAPTERS__2__MAX_RETRIES=3
EVENT_NOTIF_HTTP__PORT=8080
# mqtt adapter index 2
NOTIFIER__ADAPTERS_2__type=Mqtt
NOTIFIER__ADAPTERS_2__broker=mqtt.example.com
NOTIFIER__ADAPTERS_2__port=1883
NOTIFIER__ADAPTERS_2__client_id=event-notifier
NOTIFIER__ADAPTERS_2__topic=events
NOTIFIER__ADAPTERS_2__max_retries=3