@@ -89,6 +89,13 @@ def build_main_arg_parser() -> argparse.ArgumentParser:
89
89
90
90
@dataclass
91
91
class RunOptions :
92
+ """RunOptions dataclass to store the configuration options.
93
+
94
+ Most of options don't have default values because they are expected
95
+ to be set by the user either in the configuration file or through
96
+ command line arguments.
97
+ """
98
+
92
99
config_file : str
93
100
verbose : bool
94
101
file_log : bool
@@ -102,12 +109,36 @@ class RunOptions:
102
109
pyscicat : Optional [str ] = None
103
110
104
111
112
+ @dataclass
113
+ class kafkaOptions :
114
+ """KafkaOptions dataclass to store the configuration options.
115
+
116
+ Default values are provided as they are not
117
+ expected to be set by command line arguments.
118
+ """
119
+
120
+ topics : list [str ] | str = "KAFKA_TOPIC_1,KAFKA_TOPIC_2"
121
+ """List of Kafka topics. Multiple topics can be separated by commas."""
122
+ group_id : str = "GROUP_ID"
123
+ """Kafka consumer group ID."""
124
+ bootstrap_servers : list [str ] | str = "localhost:9092"
125
+ """List of Kafka bootstrap servers. Multiple servers can be separated by commas."""
126
+ individual_message_commit : bool = False
127
+ """Commit for each topic individually."""
128
+ enable_auto_commit : bool = True
129
+ """Enable Kafka auto commit."""
130
+ auto_offset_reset : str = "earliest"
131
+ """Kafka auto offset reset."""
132
+
133
+
105
134
@dataclass
106
135
class ScicatConfig :
107
136
original_dict : Mapping
108
137
"""Original configuration dictionary in the json file."""
109
138
run_options : RunOptions
110
139
"""Merged configuration dictionary with command line arguments."""
140
+ kafka_options : kafkaOptions
141
+ """Kafka configuration options read from files."""
111
142
112
143
def to_dict (self ) -> dict :
113
144
"""Return the configuration as a dictionary."""
@@ -119,7 +150,7 @@ def to_dict(self) -> dict:
119
150
if isinstance (value , Mapping ):
120
151
original_dict [key ] = dict (value )
121
152
122
- copied = ScicatConfig (original_dict , self .run_options )
153
+ copied = ScicatConfig (original_dict , self .run_options , self . kafka_options )
123
154
return asdict (copied )
124
155
125
156
@@ -153,4 +184,5 @@ def build_scicat_config(input_args: argparse.Namespace) -> ScicatConfig:
153
184
return ScicatConfig (
154
185
original_dict = MappingProxyType (config_dict ),
155
186
run_options = RunOptions (** run_option_dict ),
187
+ kafka_options = kafkaOptions (** config_dict .setdefault ('kafka' , dict ())),
156
188
)
0 commit comments