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/20 08:22:55 UTC

[GitHub] [pinot] snleee opened a new pull request, #10308: Add the support of Apache Pulsar for StreamGithubEventsCommand

snleee opened a new pull request, #10308:
URL: https://github.com/apache/pinot/pull/10308

   Make the command to be able to publish data to Apache Pulsar cluster.


-- 
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


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

Posted by "snleee (via GitHub)" <gi...@apache.org>.
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


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

Posted by "snleee (via GitHub)" <gi...@apache.org>.
snleee commented on code in PR #10308:
URL: https://github.com/apache/pinot/pull/10308#discussion_r1113319028


##########
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:
   @FelixGV Changed the try block to trigger close in case of error. Thanks for the input!



-- 
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


[GitHub] [pinot] codecov-commenter commented on pull request #10308: Add the support of Apache Pulsar for StreamGithubEventsCommand

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #10308:
URL: https://github.com/apache/pinot/pull/10308#issuecomment-1436684435

   # [Codecov](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#10308](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5106f20) into [master](https://codecov.io/gh/apache/pinot/commit/0927e94b0dce761fe65ea0a47c5e2d8a0887ac06?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0927e94) will **decrease** coverage by `33.23%`.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@              Coverage Diff              @@
   ##             master   #10308       +/-   ##
   =============================================
   - Coverage     68.41%   35.18%   -33.23%     
   + Complexity     5109      245     -4864     
   =============================================
     Files          2015     2027       +12     
     Lines        109656   110066      +410     
     Branches      16686    16716       +30     
   =============================================
   - Hits          75024    38730    -36294     
   - Misses        29283    67977    +38694     
   + Partials       5349     3359     -1990     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | integration1 | `24.38% <0.00%> (-0.23%)` | :arrow_down: |
   | integration2 | `24.59% <0.00%> (?)` | |
   | unittests1 | `?` | |
   | unittests2 | `13.73% <0.00%> (+0.04%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...in/stream/pulsar/PulsarStreamMetadataProvider.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcGx1Z2lucy9waW5vdC1zdHJlYW0taW5nZXN0aW9uL3Bpbm90LXB1bHNhci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcGx1Z2luL3N0cmVhbS9wdWxzYXIvUHVsc2FyU3RyZWFtTWV0YWRhdGFQcm92aWRlci5qYXZh) | `13.55% <0.00%> (ø)` | |
   | [...lugin/stream/pulsar/server/PulsarDataProducer.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcGx1Z2lucy9waW5vdC1zdHJlYW0taW5nZXN0aW9uL3Bpbm90LXB1bHNhci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcGx1Z2luL3N0cmVhbS9wdWxzYXIvc2VydmVyL1B1bHNhckRhdGFQcm9kdWNlci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...in/java/org/apache/pinot/spi/utils/BytesUtils.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvdXRpbHMvQnl0ZXNVdGlscy5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...java/org/apache/pinot/spi/trace/BaseRecording.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvdHJhY2UvQmFzZVJlY29yZGluZy5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...java/org/apache/pinot/spi/trace/NoOpRecording.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvdHJhY2UvTm9PcFJlY29yZGluZy5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...ava/org/apache/pinot/spi/config/table/FSTType.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3RhYmxlL0ZTVFR5cGUuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...ava/org/apache/pinot/spi/config/user/RoleType.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3VzZXIvUm9sZVR5cGUuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...ava/org/apache/pinot/spi/data/MetricFieldSpec.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvZGF0YS9NZXRyaWNGaWVsZFNwZWMuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...ava/org/apache/pinot/spi/stream/StreamMessage.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvc3RyZWFtL1N0cmVhbU1lc3NhZ2UuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...java/org/apache/pinot/common/tier/TierFactory.java](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vdGllci9UaWVyRmFjdG9yeS5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | ... and [1248 more](https://codecov.io/gh/apache/pinot/pull/10308?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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


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

Posted by "snleee (via GitHub)" <gi...@apache.org>.
snleee commented on code in PR #10308:
URL: https://github.com/apache/pinot/pull/10308#discussion_r1113317397


##########
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();
+      producer.send(payload);
+      producer.close();
+    } catch (PulsarClientException e) {
+      LOGGER.error("Failed to produce message for topic: " + topic, e);
+    }
+  }
+
+  @Override
+  public void produce(String topic, byte[] key, byte[] payload) {
+    try {
+      Producer<byte[]> producer = _pulsarClient.newProducer().topic(topic).create();
+      producer.newMessage().key(Base64.getEncoder().encodeToString(key)).value(payload).send();
+      producer.send(payload);

Review Comment:
   Thanks for inputs! I addressed your comments.



-- 
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


[GitHub] [pinot] snleee merged pull request #10308: Add the support of Apache Pulsar for StreamGithubEventsCommand

Posted by "snleee (via GitHub)" <gi...@apache.org>.
snleee merged PR #10308:
URL: https://github.com/apache/pinot/pull/10308


-- 
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


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

Posted by "KKcorps (via GitHub)" <gi...@apache.org>.
KKcorps commented on code in PR #10308:
URL: https://github.com/apache/pinot/pull/10308#discussion_r1111757055


##########
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:
   Why create a new producer instance for each payload? Can we reuse it?



-- 
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


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

Posted by "FelixGV (via GitHub)" <gi...@apache.org>.
FelixGV commented on code in PR #10308:
URL: https://github.com/apache/pinot/pull/10308#discussion_r1113260200


##########
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();
+      producer.send(payload);
+      producer.close();
+    } catch (PulsarClientException e) {
+      LOGGER.error("Failed to produce message for topic: " + topic, e);
+    }
+  }
+
+  @Override
+  public void produce(String topic, byte[] key, byte[] payload) {
+    try {
+      Producer<byte[]> producer = _pulsarClient.newProducer().topic(topic).create();
+      producer.newMessage().key(Base64.getEncoder().encodeToString(key)).value(payload).send();
+      producer.send(payload);

Review Comment:
   I'm not super familiar with the Pulsar API so maybe this is as intended, but won't this code here produce twice, once with a key and a value, and a second time with just a value?



##########
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:
   If we do create/close clients here (as opposed to reusing them), should we use `try-with-resources`? The current code seems like it could leak clients if they throw during `send()`.



-- 
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