co.decodable.sdk.pipeline.internal.DecodableStreamSinkBuilderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of decodable-pipeline-sdk Show documentation
Show all versions of decodable-pipeline-sdk Show documentation
A software development kit for implementing Apache Flink jobs and running them on Decodable
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright Decodable, Inc.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package co.decodable.sdk.pipeline.internal;
import co.decodable.sdk.pipeline.DecodableStreamSink;
import co.decodable.sdk.pipeline.DecodableStreamSinkBuilder;
import co.decodable.sdk.pipeline.EnvironmentAccess;
import co.decodable.sdk.pipeline.internal.config.StreamConfig;
import co.decodable.sdk.pipeline.internal.config.StreamConfigMapping;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import org.apache.flink.api.common.serialization.SerializationSchema;
import org.apache.flink.connector.base.DeliveryGuarantee;
import org.apache.flink.connector.kafka.sink.KafkaRecordSerializationSchema;
import org.apache.flink.connector.kafka.sink.KafkaSink;
public class DecodableStreamSinkBuilderImpl implements DecodableStreamSinkBuilder {
private String streamId;
private String streamName;
private SerializationSchema serializationSchema;
@Override
public DecodableStreamSinkBuilder withStreamName(String streamName) {
this.streamName = streamName;
return this;
}
@Override
public DecodableStreamSinkBuilder withStreamId(String streamId) {
this.streamId = streamId;
return this;
}
@Override
public DecodableStreamSinkBuilder withSerializationSchema(
SerializationSchema serializationSchema) {
this.serializationSchema = serializationSchema;
return this;
}
@Override
public DecodableStreamSink build() {
Objects.requireNonNull(serializationSchema, "serializationSchema");
Map environment =
EnvironmentAccess.getEnvironment().getEnvironmentConfiguration();
StreamConfig streamConfig =
new StreamConfigMapping(environment).determineConfig(streamName, streamId);
KafkaSink delegate =
KafkaSink.builder()
.setBootstrapServers(streamConfig.bootstrapServers())
.setRecordSerializer(
KafkaRecordSerializationSchema.builder()
.setTopic(streamConfig.topic())
.setValueSerializationSchema(serializationSchema)
.build())
.setDeliveryGuarantee(
"exactly-once".equals(streamConfig.deliveryGuarantee())
? DeliveryGuarantee.EXACTLY_ONCE
: "at-least-once".equals(streamConfig.deliveryGuarantee())
? DeliveryGuarantee.AT_LEAST_ONCE
: DeliveryGuarantee.NONE)
.setTransactionalIdPrefix(streamConfig.transactionalIdPrefix())
.setKafkaProducerConfig(toProperties(streamConfig.kafkaProperties()))
.build();
return new DecodableStreamSinkImpl(delegate);
}
private static Properties toProperties(Map map) {
Properties p = new Properties();
p.putAll(map);
return p;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy