syhily commented on a change in pull request #17452: URL: https://github.com/apache/flink/pull/17452#discussion_r805939365
########## File path: flink-connectors/flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/sink/writer/serializer/PulsarSerializationSchema.java ########## @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.connector.pulsar.sink.writer.serializer; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.api.common.serialization.SerializationSchema; +import org.apache.flink.api.common.serialization.SerializationSchema.InitializationContext; +import org.apache.flink.connector.pulsar.common.schema.PulsarSchema; +import org.apache.flink.connector.pulsar.sink.config.SinkConfiguration; +import org.apache.flink.connector.pulsar.sink.writer.context.PulsarSinkContext; + +import org.apache.pulsar.client.api.Schema; +import org.apache.pulsar.client.api.TypedMessageBuilder; +import org.apache.pulsar.common.schema.KeyValue; + +import java.io.Serializable; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * The serialization schema for how to serialize record into Pulsar. + * + * @param <IN> The message type send to Pulsar. + */ +@PublicEvolving +public interface PulsarSerializationSchema<IN> extends Serializable { + + /** + * Initialization method for the schema. It is called before the actual working methods {@link + * #serialize(Object)} and thus suitable for one time setup work. + * + * <p>The provided {@link InitializationContext} can be used to access additional features such + * as e.g. registering user metrics. + * + * @param initializationContext Contextual information that can be used during initialization. + * @param sinkContext runtime information i.e. partitions, subtaskId + * @param sinkConfiguration All the configure options for Pulsar sink. You can add custom + * options. + */ + default void open( + InitializationContext initializationContext, + PulsarSinkContext sinkContext, + SinkConfiguration sinkConfiguration) + throws Exception {} + + /** + * Serializes given element into bytes. Property {@link TypedMessageBuilder#value(Object)}. + * + * @param element element to be serialized + */ + byte[] serialize(IN element); Review comment: We can wrap the `TypedMessageBuilder` into a custom message builder interface and only expose the required methods? ``` public interface MessageBuilder { MessageBuilder orderingKey(byte[] orderingKey); MessageBuilder properties(Map<String, String> properties); ... } public class PulsarMessageBuilder implements MessageBuilder { // TODO } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
