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
!20
Draft: Uc1 teetime implementation
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft: Uc1 teetime implementation
stu203404/theodolite:uc1-teetime
into
main
Overview
10
Commits
45
Pipelines
0
Changes
20
Open
Lorenz Boguhn
requested to merge
stu203404/theodolite:uc1-teetime
into
main
5 years ago
Overview
10
Commits
45
Pipelines
0
Changes
20
Expand
Implements
#24
Edited
3 years ago
by
Sören Henning
0
0
Merge request reports
Compare
main
version 14
c8a92573
4 years ago
version 13
c8a92573
4 years ago
version 12
dabb9a82
4 years ago
version 11
40270715
4 years ago
version 10
58c2e255
4 years ago
version 9
cf73aa59
4 years ago
version 8
96da07c0
4 years ago
version 7
db622b68
4 years ago
version 6
f1d1b3e1
4 years ago
version 5
3942ab8e
4 years ago
version 4
d683d323
5 years ago
version 3
46d44d77
5 years ago
version 2
9f31c543
5 years ago
version 1
77e3f2a7
5 years ago
main (base)
and
latest version
latest version
c8a92573
45 commits,
3 years ago
version 14
c8a92573
45 commits,
4 years ago
version 13
c8a92573
45 commits,
4 years ago
version 12
dabb9a82
43 commits,
4 years ago
version 11
40270715
42 commits,
4 years ago
version 10
58c2e255
39 commits,
4 years ago
version 9
cf73aa59
37 commits,
4 years ago
version 8
96da07c0
36 commits,
4 years ago
version 7
db622b68
35 commits,
4 years ago
version 6
f1d1b3e1
27 commits,
4 years ago
version 5
3942ab8e
25 commits,
4 years ago
version 4
d683d323
23 commits,
5 years ago
version 3
46d44d77
21 commits,
5 years ago
version 2
9f31c543
20 commits,
5 years ago
version 1
77e3f2a7
19 commits,
5 years ago
20 files
+
752
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
20
Search (e.g. *.vue) (Ctrl+P)
application-teetime-commons/src/main/java/theodolite/commons/teetime/communication/KafkaRecordsReader.java
0 → 100644
+
99
−
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