# BLS RCU Action Server

## Overview
Backend service for processing RCU action events from Kafka, parsing them, and storing them in PostgreSQL. Includes error handling via Redis and heartbeat monitoring.

## Architecture
- **Input**: Kafka Topic (`blwlog4Nodejs-rcu-action-topic` or configured via env)
- **Processing**: Node.js Service
  - **Consumer**: `kafka-node` consumer group
  - **Parser**: Parses JSON messages, handles UDP raw data decoding
  - **Database**: PostgreSQL (Batch insert)
  - **Error Handling**: Redis List (`error_queue`) for failed messages + Retry mechanism
- **Output**: PostgreSQL Table (`rcu_action_events`)

## Features
- **Loop Name Enrichment**: Enriches event data with `loop_name` by matching `device_id` and `dev_addr` against metadata cached from `temporary_project` tables (refreshed daily).

## Configuration (Environment Variables)
The project is configured via `.env`. Key variables:
- **Kafka**: `KAFKA_BROKERS`, `KAFKA_TOPIC`, `KAFKA_SASL_USERNAME`, `KAFKA_SASL_PASSWORD`
- **Database**: `DB_HOST`, `DB_PORT`, `DB_USER`, `DB_PASSWORD`, `DB_DATABASE`, `DB_SSL`
- **Redis**: `REDIS_HOST`, `REDIS_PORT`, `REDIS_PASSWORD`

## Development Constraints
- **Schema**: Must strictly follow `docs/readme.md`.
- **Database**: Do not alter Schema Name (`rcu_action`) or Table Name (`rcu_action_events`) unless explicitly requested.
