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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sören Henning
theodolite
Merge requests
!51
Draft: Uc3 TeeTime implementation
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft: Uc3 TeeTime implementation
stu203404/theodolite:uc3-teetime
into
main
Overview
1
Commits
76
Pipelines
0
Changes
27
Open
Lorenz Boguhn
requested to merge
stu203404/theodolite:uc3-teetime
into
main
4 years ago
Overview
1
Commits
76
Pipelines
0
Changes
27
Expand
Implementation of UC3: Downsampling with TeeTime
Implements
#26
Edited
3 years ago
by
Sören Henning
0
0
Merge request reports
Compare
main
version 2
c39e90c2
4 years ago
version 1
c39e90c2
4 years ago
main (base)
and
latest version
latest version
c39e90c2
76 commits,
3 years ago
version 2
c39e90c2
76 commits,
4 years ago
version 1
c39e90c2
76 commits,
4 years ago
27 files
+
1086
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
27
Search (e.g. *.vue) (Ctrl+P)
application-teetime-commons/src/main/java/theodolite/commons/teetime/communication/KafkaRecordsReader.java
0 → 100644
+
100
−
0
Options
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