TNT4J-Streams can load configuration not only from local configuration files but also from data stored in ZooKeeper nodes. Using ZooKeeper enables centralized handling of configuration data.
TNT4J-Streams can load configuration stored in ZooKeeper at application startup and can also monitor referenced ZooKeeper nodes for changes, allowing configuration updates to be applied at runtime.
Uploading Configuration Data to ZooKeeper
To upload TNT4J-Streams configuration files to ZooKeeper nodes, use the ZKConfigInit utility. It accepts the following program arguments:
-f:— Path to the uploader utility configuration file. Required.-c— Cleans ZooKeeper nodes that contain TNT4J-Streams configuration. Optional.
Run the utility via:
./bin/zk-init-cfg.bat(Windows) or./bin/zk-init-cfg.sh(Linux/macOS)
By default, it uses the uploader configuration file: ./config/zk-init-cfg.properties.
Uploader configuration (zk-init-cfg.properties) sample
# ZooKeeper server parameters zk.conn=localhost:2181 #zk.conn.timeout=5000 zk.streams.path=/tnt4j-streams # generic app configurations config.logger=../config/log4j2.xml config.tnt4j=../config/tnt4j.properties config.tnt4j-kafka=./config/tnt4j-kafka.properties # core module samples configurations samples.core.ajax=../samples/ajax/tnt-data-source.xml samples.core.angular-js-tracing=../samples/angular-js-tracing/tnt-data-source.xml samples.core.single-log=../samples/single-log/tnt-data-source.xml ...
zk.*properties define ZooKeeper connection settings.
zk.streams.path defines the root ZooKeeper node for streams configuration. All other configuration nodes will be uploaded under this root path.
Do not start your configuration-file–referencing properties with the zk. prefix. Such properties are reserved and will be ignored by the uploader; any files referenced by them will not be uploaded.
config.*andsamples.*properties map local streams configuration files to ZooKeeper nodes.
Mapping rule: The property name becomes the ZooKeeper node path (relative tozk.streams.path), and the property value is the file path whose contents are uploaded to that node.For example, the property name
samples.core.single-logmaps to the ZooKeeper node path/samples/core/single-log(full upload path:/tnt4j-streams/samples/core/single-log).
You may choose property names to fit your environment, but they must be valid properties and must translate into a valid ZooKeeper node path.
Loading ZooKeeper-Stored Configuration Data
To make TNT4J-Streams load configuration from ZooKeeper, use the program argument -z: referencing the TNT4J-Streams ZooKeeper configuration file, e.g.,-z:./tnt4j-streams-core/samples/zookeeper-cfg/stream-zk.properties.
The program argument -z: can be used in conjunction with the -f: argument. In this case, the streams will first attempt to load the configuration stored in ZooKeeper. If that fails, it will fall back to the configuration file referenced by the -f: argument.
Sample TNT4J-Streams ZooKeeper configuration contents:
# ZooKeeper server parameters zk.conn=localhost:2181/tnt4j-streams #zk.conn.timeout=5000 # logger configuration: log4j properties, logback xml/groovy config.logger.zk.path=/config/logger # TNT4J configuration: properties config.tnt4j.zk.path=/config/tnt4j #config.tnt4j-kafka.zk.path=/config/tnt4j-kafka # Stream configuration: XML containing <tnt-data-source/> config.stream.zk.path=/samples/core/single-log
zk.*properties define ZooKeeper connection settings.config.logger.zk.path— ZooKeeper node path containing logger configuration data.
If absent, the system property-Dlog4j2.configurationFile(or-Dlogback.configurationFile, depending on the logging framework) is used.
Note: Currently supports log4j, log4j2, JUL, and Logback configuration handling.config.tnt4j.zk.path— ZooKeeper node path containing TNT4J configuration data.
If absent, the system property-Dtnt4j.configis used.config.tnt4j-kafka.zk.path— Reserved for TNT4J-Kafka configuration data. Not currently used. (TBD)config.stream.zk.path— ZooKeeper node path containing the stream configuration (XML with<tnt-data-source/>).
If absent, the configuration file specified via the-f:program argument is used.
Streams Registry
TNT4J-Streams can also contain all ZooKeeper configuration in a single file. See <tnt4j-streams>/config/streams-zk.properties.
The file consists of ZooKeeper configuration registry entries; each entry has two properties (except the zk.* properties used to configure the ZooKeeper connection):
cfg.entity.id.zk.path— Defines the ZooKeeper node path containing the entity’s configuration data.
Note: The actual path in the ZooKeeper ensemble may not yet exist; it will be created on demand.cfg.entity.id.cfg.file— Defines the configuration file path to upload to the ZooKeeper node if the node does not exist or is empty.
Sample streams ZooKeeper configuration (registry-style) contents
########################### ZooKeeper server parameters ########################### # ZooKeeper connection string zk.conn=localhost:2181/tnt4j-streams # ZooKeeper connection timeout #zk.conn.timeout=5000 # ZooKeeper path of TNT4J-Streams root node location zk.streams.path=/tnt4j-streams ########################### Generic app configurations ########################### # Logger configuration: log4j properties, logback xml/groovy config.logger.zk.path=/config/logger config.logger.cfg.file=../config/log4j2.xml # TNT4J configuration config.tnt4j.zk.path=/config/tnt4j config.tnt4j.cfg.file=../config/tnt4j.properties # TNT4J-Kafka configuration (used by KafkaEventSink) config.tnt4j-kafka.zk.path=/config/tnt4j-kafka config.tnt4j-kafka.cfg.file=../config/tnt4j-kafka.properties ########################### Sample Streams configurations ########################### ### core module samples configurations # sample stream: samples.core.ajax samples.core.ajax.zk.path=/samples/core/ajax samples.core.ajax.cfg.file=../samples/ajax/tnt-data-source.xml # sample stream: samples.core.multiple-logs samples.core.multiple-logs.zk.path=/samples/core/multiple-logs samples.core.multiple-logs.cfg.file=../samples/multiple-logs/tnt-data-source.xml # sample stream: samples.core.piping-stream samples.core.piping-stream.zk.path=/samples/core/piping-stream samples.core.piping-stream.cfg.file=../samples/piping-stream/parsers.xml # sample stream: samples.core.single-log samples.core.single-log.zk.path=/samples/core/single-log samples.core.single-log.cfg.file=../samples/single-log/tnt-data-source.xml ...
zk.*properties defines ZK connection configuration settings.config.*properties defines configuration entities forlogger,tnt4jandtnt4j-kafka.samples.*properties defines configuration entities for sample steams.
Also see Loading ZooKeeper stored configuration data.
When using the registry-style ZooKeeper configuration, any missing configuration entity ZK node data is automatically uploaded on demand from the file referenced by that entity’s *.cfg.file property.
Running with registry-style ZooKeeper configuration
Define these program arguments: -z:<cfg_file> -sid:<stream_id>, for example:
-z:./config/streams-zk.properties -sid:samples.core.single-log
single-log. See Single Log file for sample details.