Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flink] Allow to specify a custom Pulsar producer #3894

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ public FlinkPulsarProducer(String serviceUrl,
String defaultTopicName,
SerializationSchema<IN> serializationSchema,
PulsarKeyExtractor<IN> keyExtractor) {
this(serviceUrl, defaultTopicName, serializationSchema, keyExtractor, null);
}

public FlinkPulsarProducer(String serviceUrl,
String defaultTopicName,
SerializationSchema<IN> serializationSchema,
PulsarKeyExtractor<IN> keyExtractor,
Producer<byte[]> producer) {
checkArgument(StringUtils.isNotBlank(serviceUrl), "Service url cannot be blank");
checkArgument(StringUtils.isNotBlank(defaultTopicName), "TopicName cannot be blank");
this.serviceUrl = serviceUrl;
this.defaultTopicName = defaultTopicName;
this.schema = checkNotNull(serializationSchema, "Serialization Schema not set");
this.flinkPulsarKeyExtractor = getOrNullKeyExtractor(keyExtractor);
ClosureCleaner.ensureSerializable(serializationSchema);
this.producer = producer;
}

// ---------------------------------- Properties --------------------------
Expand Down Expand Up @@ -185,7 +194,10 @@ private Producer<byte[]> createProducer() throws Exception {
*/
@Override
public void open(Configuration parameters) throws Exception {
this.producer = createProducer();
if (producer == null) {
// If no custom producer was specified create a default one
this.producer = createProducer();
}

RuntimeContext ctx = getRuntimeContext();

Expand Down