Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
theodolite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sören Henning
theodolite
Merge requests
!50
Draft: Uc2 TeeTime implementation
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Open
Draft: Uc2 TeeTime implementation
stu203404/theodolite:uc2-teetime
into
main
Overview
1
Commits
87
Pipelines
0
Changes
37
Open
Draft: Uc2 TeeTime implementation
Lorenz Boguhn
requested to merge
stu203404/theodolite:uc2-teetime
into
main
Oct 12, 2020
Overview
1
Commits
87
Pipelines
0
Changes
37
Implementation of UC2: Hierarchical Aggregation with TeeTime
Implements
#25
Edited
Nov 13, 2021
by
Sören Henning
0
0
Merge request reports
Compare
main
version 5
57fe0b2c
Jun 29, 2021
version 4
57fe0b2c
Oct 12, 2020
version 3
94bfca0e
Oct 12, 2020
version 2
e09c2b4d
Oct 12, 2020
version 1
30d13477
Oct 12, 2020
main (base)
and
latest version
latest version
57fe0b2c
87 commits,
Jul 15, 2022
version 5
57fe0b2c
87 commits,
Jun 29, 2021
version 4
57fe0b2c
87 commits,
Oct 12, 2020
version 3
94bfca0e
85 commits,
Oct 12, 2020
version 2
e09c2b4d
84 commits,
Oct 12, 2020
version 1
30d13477
83 commits,
Oct 12, 2020
37 files
+
1779
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
37
application-teetime-commons/src/main/java/theodolite/commons/teetime/communication/KafkaRecordsReader.java
0 → 100644
+
100
−
0
View file @ 57fe0b2c
Edit in single-file editor
Open in Web IDE
package
theodolite.commons.teetime.communication
;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.Properties
;
import
org.apache.commons.configuration2.Configuration
;
import
org.apache.kafka.clients.consumer.ConsumerRecords
;
import
org.apache.kafka.clients.consumer.KafkaConsumer
;
import
org.apache.kafka.common.serialization.StringDeserializer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
teetime.framework.AbstractProducerStage
;
import
teetime.framework.OutputPort
;
import
theodolite.commons.teetime.config.ConfigurationKeys
;
import
titan.ccp.common.kafka.avro.SchemaRegistryAvroSerdeFactory
;
import
titan.ccp.model.records.ActivePowerRecord
;
/**
* TeeTime Producer change to Reader.
*
*/
public
class
KafkaRecordsReader
extends
AbstractProducerStage
<
ConsumerRecords
<
String
,
ActivePowerRecord
>>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
KafkaRecordsReader
.
class
);
private
final
KafkaConsumer
<
String
,
ActivePowerRecord
>
consumer
;
private
final
int
commitIntervalMs
;
private
final
OutputPort
<
Object
>
startPort
=
this
.
createOutputPort
();
/**
* TeeTime Producer stage that reads from Kafka.
*/
public
KafkaRecordsReader
(
final
Configuration
kafkaconfig
)
{
super
();
final
Configuration
config
=
kafkaconfig
;
this
.
commitIntervalMs
=
Integer
.
parseInt
(
config
.
getString
(
ConfigurationKeys
.
COMMIT_INTERVAL_MS
));
final
Properties
props
=
new
Properties
();
props
.
put
(
"application.name"
,
config
.
getString
(
ConfigurationKeys
.
APPLICATION_NAME
));
props
.
put
(
"application.version"
,
config
.
getString
(
ConfigurationKeys
.
APPLICATION_VERSION
));
props
.
put
(
"auto.commit.interval.ms"
,
config
.
getString
(
ConfigurationKeys
.
COMMIT_INTERVAL_MS
));
props
.
put
(
"bootstrap.servers"
,
config
.
getString
(
ConfigurationKeys
.
KAFKA_BOOTSTRAP_SERVERS
));
props
.
put
(
"group.id"
,
"test"
);
final
SchemaRegistryAvroSerdeFactory
serdes
=
new
SchemaRegistryAvroSerdeFactory
(
kafkaconfig
.
getString
(
ConfigurationKeys
.
SCHEMA_REGISTRY_URL
));
final
ArrayList
<
String
>
inputTopics
=
new
ArrayList
<>();
inputTopics
.
add
(
config
.
getString
(
ConfigurationKeys
.
KAFKA_INPUT_TOPIC
));
this
.
consumer
=
new
KafkaConsumer
<>(
props
,
new
StringDeserializer
(),
serdes
.<
ActivePowerRecord
>
forValues
().
deserializer
());
this
.
consumer
.
subscribe
(
inputTopics
);
}
@Override
protected
void
execute
()
{
try
{
this
.
runConsumer
();
}
catch
(
final
InterruptedException
e
)
{
LOGGER
.
error
(
e
.
toString
());
}
}
private
void
runConsumer
()
throws
InterruptedException
{
final
Duration
pollTime
=
Duration
.
ofMillis
(
commitIntervalMs
);
while
(
true
)
{
final
ConsumerRecords
<
String
,
ActivePowerRecord
>
consumerRecords
=
this
.
consumer
.
poll
(
pollTime
);
if
(!
consumerRecords
.
isEmpty
())
{
this
.
getOutputPort
().
send
(
consumerRecords
);
this
.
consumer
.
commitAsync
();
}
this
.
consumer
.
commitAsync
();
}
}
@Override
protected
void
onTerminating
()
{
this
.
consumer
.
close
();
super
.
onTerminating
();
}
public
OutputPort
<
Object
>
getStartPort
()
{
return
startPort
;
}
}
Loading