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
Commits
dbb420b1
Commit
dbb420b1
authored
3 years ago
by
Lorenz Boguhn
Committed by
Lorenz Boguhn
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Clean beam-commons project
parent
aa2706f9
No related branches found
No related tags found
1 merge request
!187
Migrate Beam benchmark implementation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theodolite-benchmarks/beam-commons/src/main/java/theodolite/commons/beam/kafka/KafkaWriterTransformation.java
+14
-11
14 additions, 11 deletions
...odolite/commons/beam/kafka/KafkaWriterTransformation.java
with
14 additions
and
11 deletions
theodolite-benchmarks/beam-commons/src/main/java/theodolite/commons/beam/kafka/KafkaWriterTransformation.java
+
14
−
11
View file @
dbb420b1
package
theodolite.commons.beam.kafka
;
import
java.util.Properties
;
import
org.apache.beam.sdk.io.kafka.KafkaIO
;
import
org.apache.beam.sdk.transforms.PTransform
;
import
org.apache.beam.sdk.values.KV
;
...
...
@@ -9,25 +8,29 @@ import org.apache.beam.sdk.values.PDone;
import
org.apache.kafka.common.serialization.Serializer
;
import
org.apache.kafka.common.serialization.StringSerializer
;
public
class
KafkaWriterTransformation
<
K
>
extends
PTransform
<
PCollection
<
KV
<
String
,
K
>>,
PDone
>
{
/**
* Wrapper for a Kafka writing Transformation
* where the value type can be generic.
* @param <T> type of the value.
*/
public
class
KafkaWriterTransformation
<
T
extends
Serializer
>
extends
PTransform
<
PCollection
<
KV
<
String
,
T
>>,
PDone
>
{
private
static
final
long
serialVersionUID
=
3171423303843174723L
;
private
final
PTransform
<
PCollection
<
KV
<
String
,
K
>>,
PDone
>
writer
;
private
final
PTransform
<
PCollection
<
KV
<
String
,
T
>>,
PDone
>
writer
;
/**
* Creates a new kafka writer transformation.
*/
public
KafkaWriterTransformation
(
final
String
bootstrapServer
,
final
String
outputTopic
,
final
java
.
lang
.
Class
<?
extends
org
.
apache
.
kafka
.
common
.
serialization
.
Serializer
<
K
>>
valueSerializer
)
{
final
Class
<?
extends
Serializer
<
T
>>
valueSerializer
)
{
super
();
// Check if boostrap server and outputTopic are defined
if
(
bootstrapServer
.
isEmpty
()
||
outputTopic
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"bootstrapServer or outputTopic missing"
);
}
this
.
writer
=
KafkaIO
.<
String
,
K
>
write
()
this
.
writer
=
KafkaIO
.<
String
,
T
>
write
()
.
withBootstrapServers
(
bootstrapServer
)
.
withTopic
(
outputTopic
)
.
withKeySerializer
(
StringSerializer
.
class
)
...
...
@@ -36,7 +39,7 @@ public class KafkaWriterTransformation<K> extends
}
@Override
public
PDone
expand
(
PCollection
<
KV
<
String
,
K
>>
input
)
{
public
PDone
expand
(
final
PCollection
<
KV
<
String
,
T
>>
input
)
{
return
input
.
apply
(
this
.
writer
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment