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
!253
Draft: Add PubSub Lite load generator
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft: Add PubSub Lite load generator
pubsublite-load-generator
into
main
Overview
0
Commits
1
Pipelines
2
Changes
2
Open
Sören Henning
requested to merge
pubsublite-load-generator
into
main
3 years ago
Overview
0
Commits
1
Pipelines
2
Changes
2
Expand
0
0
Merge request reports
Compare
main
version 1
277c5d0f
3 years ago
main (HEAD)
and
latest version
latest version
277c5d0f
1 commit,
2 years ago
version 1
277c5d0f
1 commit,
3 years ago
2 files
+
71
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
theodolite-benchmarks/load-generator-commons/src/main/java/rocks/theodolite/benchmarks/loadgenerator/PubSubLiteRecordSender.java
0 → 100644
+
69
−
0
Options
package
rocks.theodolite.benchmarks.loadgenerator
;
import
com.google.cloud.pubsublite.CloudRegion
;
import
com.google.cloud.pubsublite.CloudZone
;
import
com.google.cloud.pubsublite.ProjectNumber
;
import
com.google.cloud.pubsublite.TopicName
;
import
com.google.cloud.pubsublite.TopicPath
;
import
com.google.cloud.pubsublite.kafka.ProducerSettings
;
import
java.util.function.Function
;
import
org.apache.kafka.clients.producer.ProducerRecord
;
import
org.apache.kafka.common.serialization.Serializer
;
/**
* Sends monitoring records to Pub/Sub Lite. This class uses a Kafka producer internally.
*
* @param <T> Record type to send.
*/
public
class
PubSubLiteRecordSender
<
T
>
extends
KafkaRecordSenderImpl
<
T
,
byte
[],
byte
[]>
{
/**
* Create a new {@link PubSubLiteRecordSender}.
*/
public
PubSubLiteRecordSender
(
final
TopicPath
topicPath
,
final
Serializer
<
T
>
serializer
,
final
Function
<
T
,
String
>
keyAccessor
,
final
Function
<
T
,
Long
>
timestampAccessor
)
{
super
(
ProducerSettings
.
newBuilder
().
setTopicPath
(
topicPath
).
build
().
instantiate
(),
new
PubSubLiteRecordFactory
<
T
>(
serializer
),
topicPath
.
toString
(),
keyAccessor
,
timestampAccessor
);
}
/**
* Create a {@link TopicPath} from the provided Google Cloud settings.
*/
public
static
TopicPath
buildTopicPath
(
final
String
cloudRegion
,
final
char
zoneId
,
final
long
projectNumber
,
final
String
topicId
)
{
return
TopicPath
.
newBuilder
()
.
setLocation
(
CloudZone
.
of
(
CloudRegion
.
of
(
cloudRegion
),
zoneId
))
.
setProject
(
ProjectNumber
.
of
(
projectNumber
))
.
setName
(
TopicName
.
of
(
topicId
))
.
build
();
}
private
static
class
PubSubLiteRecordFactory
<
T
>
implements
KafkaRecordFactory
<
T
,
byte
[],
byte
[]>
{
private
final
Serializer
<
T
>
serializer
;
public
PubSubLiteRecordFactory
(
final
Serializer
<
T
>
serializer
)
{
this
.
serializer
=
serializer
;
}
@Override
public
ProducerRecord
<
byte
[],
byte
[]>
create
(
final
String
topic
,
final
String
key
,
final
T
value
,
final
long
timestamp
)
{
return
new
ProducerRecord
<>(
topic
,
null
,
timestamp
,
key
.
getBytes
(),
this
.
serializer
.
serialize
(
topic
,
value
));
}
}
}
Loading