You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/09/20 16:21:59 UTC

[GitHub] chrismiller commented on a change in pull request #5845: [FLINK-9168][flink-connectors]Pulsar Sink connector

chrismiller commented on a change in pull request #5845: [FLINK-9168][flink-connectors]Pulsar Sink connector
URL: https://github.com/apache/flink/pull/5845#discussion_r219230230
 
 

 ##########
 File path: flink-connectors/flink-connector-pulsar/src/main/java/org/apache/flink/streaming/connectors/pulsar/FlinkPulsarProducer.java
 ##########
 @@ -0,0 +1,304 @@
+/*
+ * 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.streaming.connectors.pulsar;
+
+import org.apache.flink.api.common.functions.RuntimeContext;
+import org.apache.flink.api.common.serialization.SerializationSchema;
+import org.apache.flink.api.java.ClosureCleaner;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.state.FunctionInitializationContext;
+import org.apache.flink.runtime.state.FunctionSnapshotContext;
+import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;
+import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
+import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
+import org.apache.flink.streaming.connectors.pulsar.partitioner.PulsarKeyExtractor;
+import org.apache.flink.util.SerializableObject;
+
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.MessageBuilder;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.ProducerConfiguration;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.function.Function;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Flink Sink to produce data into a Pulsar topic.
+ */
+public class FlinkPulsarProducer<IN>
+		extends RichSinkFunction<IN>
+		implements CheckpointedFunction {
+
+	private static final Logger LOG = LoggerFactory.getLogger(FlinkPulsarProducer.class);
+
+	/**
+	 * The pulsar service url.
+	 */
+	protected final String serviceUrl;
+
+	/**
+	 * User defined configuration for the producer.
+	 */
+	protected final ProducerConfiguration producerConfig;
+
+	/**
+	 * The name of the default topic this producer is writing data to.
+	 */
+	protected final String defaultTopicName;
+
+	/**
+	 * (Serializable) SerializationSchema for turning objects used with Flink into.
+	 * byte[] for Pulsar.
+	 */
+	protected final SerializationSchema<IN> schema;
+
+	/**
+	 * User-provided key extractor for assigning a key to a pulsar message.
+	 */
+	protected final PulsarKeyExtractor<IN> flinkPulsarKeyExtractor;
+
+	/**
+	 * Produce Mode.
+	 */
+	protected PulsarProduceMode produceMode = PulsarProduceMode.AT_LEAST_ONE;
+
+	/**
+	 * If true, the producer will wait until all outstanding records have been send to the broker.
+	 */
+	protected boolean flushOnCheckpoint;
+
+	// -------------------------------- Runtime fields ------------------------------------------
+
+	/** KafkaProducer instance. */
+	protected transient Producer producer;
+
+	/** The callback than handles error propagation or logging callbacks. */
+	protected transient Function<MessageId, MessageId> successCallback = msgId -> {
 
 Review comment:
   This won't deserialise correctly, it will end up null. The solution is to initialise successCallback in the open() method instead, similar to how failureCallback is initialised.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services