You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "snleee (via GitHub)" <gi...@apache.org> on 2023/02/21 15:49:33 UTC

[GitHub] [pinot] snleee commented on a diff in pull request #10308: Add the support of Apache Pulsar for StreamGithubEventsCommand

snleee commented on code in PR #10308:
URL: https://github.com/apache/pinot/pull/10308#discussion_r1113252014


##########
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/server/PulsarDataProducer.java:
##########
@@ -0,0 +1,95 @@
+/**
+ * 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.pinot.plugin.stream.pulsar.server;
+
+import com.google.common.base.Preconditions;
+import java.util.Base64;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.StreamDataProducer;
+import org.apache.pulsar.client.api.AuthenticationFactory;
+import org.apache.pulsar.client.api.ClientBuilder;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PulsarDataProducer implements StreamDataProducer {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PulsarDataProducer.class);
+
+  public static final String BROKER_SERVICE_URL = "brokerServiceUrl";
+  public static final String TOKEN = "token";
+
+  private PulsarClient _pulsarClient;
+
+  public PulsarDataProducer() {
+  }
+
+  @Override
+  public void init(Properties props) {
+    String brokerServiceUrl = props.getProperty(BROKER_SERVICE_URL);
+    Preconditions.checkNotNull(brokerServiceUrl, "broker service url must be configured.");
+
+    ClientBuilder clientBuilder = PulsarClient.builder().serviceUrl(brokerServiceUrl);
+
+    String token = props.getProperty(TOKEN);
+    if (StringUtils.isNotEmpty(token)) {
+      try {
+        _pulsarClient = clientBuilder.authentication(AuthenticationFactory.token(token)).build();
+      } catch (PulsarClientException e) {
+        throw new IllegalArgumentException("Failed to create pulsar client");
+      }
+    }
+  }
+
+  @Override
+  public void produce(String topic, byte[] payload) {
+    try {
+      Producer<byte[]> producer = _pulsarClient.newProducer().topic(topic).create();

Review Comment:
   Pulsar takes `topic` as an input when creating a producer. We can probably add the client cache. This is currently mainly added for publishing events for github events data. I will add the TODO comment and will address this.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org