Because TNT4J-Streams is based on TNT4J, you must configure TNT4J first (if you have not done this yet). The default location of the tnt4j.properties file is the project config directory. At a minimum, make one change:event.sink.factory.Token: YOUR-TOKEN — replace YOUR-TOKEN with the meshIQ token assigned to you.
To define the tnt4j.properties file location, use the system property, e.g.:-Dtnt4j.config="./config/tnt4j.properties".
For more information on TNT4J and tnt4j.properties, see the TNT4J Wiki and TNT4J -Track and Trace API for Java.
Details on JESL-related configuration can be found in the JESL - jKool Event Streaming Library.
Basic TNT4J Configuration for TNT4J-Streams
Fill in the Configuration Template
Replace
<YOUR XXXX>placeholders with values for your environment.Replace
<YOUR EVENT SINK CONFIGURATION>with the configuration of the activity events sink you will use.
It is
not recommended to use
BufferedEventSinkFactory (or any
other asynchronous sinks) with TNT4J-Streams. Streams and sinks are meant to
act in sync, especially when the sink (e.g.,
jKoolCloud,
MQTT,
Kafka) uses network communication.
# Stanza used for TNT4J-Streams sources
{
source: com.jkoolcloud.tnt4j.streams
source.factory: com.jkoolcloud.tnt4j.source.SourceFactoryImpl
source.factory.GEOADDR: <YOUR GEO ADDRESS>
source.factory.DATACENTER: <YOUR DATA CENTER NAME>
source.factory.RootFQN: RUNTIME=?#SERVER=?#NETADDR=?#DATACENTER=?#GEOADDR=?
source.factory.RootSSN: tnt4j-streams
tracker.factory: com.jkoolcloud.tnt4j.tracker.DefaultTrackerFactory
dump.sink.factory: com.jkoolcloud.tnt4j.dump.DefaultDumpSinkFactory
tracker.default.snapshot.category: TNT4J-Streams-snapshot
# event sink configuration: destination and data format
<YOUR EVENT SINK CONFIGURATION: jKoolCloud, Kafka, MQTT, etc.>
event.formatter: com.jkoolcloud.tnt4j.format.JSONFormatter
#event.formatter.Newline: true
# Configure default sink filter based on level and time (elapsed/wait)
##event.sink.factory.Filter: com.jkoolcloud.tnt4j.filters.EventLevelTimeFilter
##event.sink.factory.Filter.Level: TRACE
# Uncomment lines below to filter out events based on elapsed time and wait time
# Timed event/activities greater or equal to given values will be logged
##event.sink.factory.Filter.ElapsedUsec: 100
##event.sink.factory.Filter.WaitUsec: 100
tracking.selector: com.jkoolcloud.tnt4j.selector.DefaultTrackingSelector
tracking.selector.Repository: com.jkoolcloud.tnt4j.repository.FileTokenRepository
}meshIQ Sink Configuration
#### jKoolCloud event sink factory configuration #### event.sink.factory: com.jkoolcloud.jesl.tnt4j.sink.JKCloudEventSinkFactory event.sink.factory.LogSink: file:./logs/tnt4j-streams-activities.log event.sink.factory.Url: https://stream.meshiq.com #event.sink.factory.Url: http://stream.meshiq.com:6580 event.sink.factory.Token: <YOUR TOKEN> #### jKoolCloud event sink factory configuration end ####
Configure Activities Log Rolling (via SLF4J)
If your TNT4J event sink configuration has the Filename property, e.g.:
#### jKoolCloud event sink factory configuration #### event.sink.factory: com.jkoolcloud.jesl.tnt4j.sink.JKCloudEventSinkFactory event.sink.factory.Filename: ./logs/tnt4j-streams-activities.log ...
then all streamed activities are logged into one text file by appending to the end of that file. Over time, the file can grow dramatically (gigabytes). To avoid this, for SocketEventSink and JKCloudEventSink you can configure logging via Log4j/SLF4J, enabling rolling by date or size.
Step 1 — Update log4j2.xml: add a dedicated appender
<Properties>
<Property name="tnt4j.activities.log.dir">./logs</Property>
<Property name="tnt4j.activities.log.filename">${tnt4j.activities.log.dir}/tnt4j-streams_activities.log</Property>
</Properties>
<Appenders>
<!-- ### branch for sink-written activity entities logger ### -->
<RollingFile name="activities_log"
fileName="${tnt4j.activities.log.filename}"
filePattern="${tnt4j.activities.log.filename}.%d{yyyyMMdd}.%i.gz"
ignoreExceptions="false" createOnDemand="true">
<Policies>
<OnStartupTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<DefaultRolloverStrategy max="30" fileIndex="min">
<Delete basePath="${tnt4j.activities.log.dir}" maxDepth="1">
<IfFileName glob="${tnt4j.activities.log.filename}.*.gz"/>
<IfLastModified age="30d"/>
<!--IfAccumulatedFileCount exceeds="30"/-->
</Delete>
</DefaultRolloverStrategy>
<PatternLayout>
<Pattern>%m%n</Pattern>
</PatternLayout>
</RollingFile>
</Appenders>
Step 2 — Update log4j2.xml: set up the logger
<Loggers>
<!-- #### streamed activity entities logger #### -->
<Logger name="com.jkoolcloud.tnt4j.streams.activities_log" level="INFO" additivity="false">
<AppenderRef ref="activities_log"/>
</Logger>
</Loggers>
Step 3 — Update tnt4j.properties: use LogSink
Replace the prior event.sink.factory.Filename with LogSink:
#### jKoolCloud event sink factory configuration #### event.sink.factory: com.jkoolcloud.jesl.tnt4j.sink.JKCloudEventSinkFactory #event.sink.factory.Filename: ./logs/tnt4j-streams-activities.log ##### streamed activity entities logging over SLF4J sink ##### ##### NOTE: logger name should match log4j2.xml-defined logger mapped to 'activities_log' appender ##### event.sink.factory.LogSink: slf4j:com.jkoolcloud.tnt4j.streams.activities_log
Kafka Sink Configuration
#### Kafka event sink factory configuration #### event.sink.factory: com.jkoolcloud.tnt4j.sink.impl.kafka.KafkaEventSinkFactory event.sink.factory.propFile: <YOUR PATH>/tnt4j-kafka.properties event.sink.factory.topic: <YOUR TOPIC> #### Kafka event sink factory configuration end ####
MQTT Sink Configuration
#### MQTT event sink factory configuration #### event.sink.factory: com.jkoolcloud.tnt4j.sink.impl.mqtt.MqttEventSinkFactory event.sink.factory.mqtt-server-url: <YOUR MQTT SERVER URL> event.sink.factory.mqtt-topic: <YOUR TOPIC> event.sink.factory.mqtt-user: <MQTT-USER> event.sink.factory.mqtt-pwd: <MQTT-PWD> #### MQTT event sink factory configuration end ####