You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/02/15 18:11:03 UTC

[GitHub] [iceberg] jackye1995 commented on a change in pull request #4073: AWS: add support for SNS and SQS listeners

jackye1995 commented on a change in pull request #4073:
URL: https://github.com/apache/iceberg/pull/4073#discussion_r807154615



##########
File path: aws/src/main/java/org/apache/iceberg/aws/sns/SNSListener.java
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.iceberg.aws.sns;
+
+import org.apache.iceberg.events.Listener;
+import org.apache.iceberg.util.EventParser;
+import org.apache.iceberg.util.Tasks;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.sns.SnsClient;
+import software.amazon.awssdk.services.sns.model.NotFoundException;
+import software.amazon.awssdk.services.sns.model.PublishRequest;
+import software.amazon.awssdk.services.sns.model.SnsException;
+
+public class SNSListener<T> implements Listener<T> {
+  private static final Logger LOG = LoggerFactory.getLogger(SNSListener.class);
+
+  private final String topicArn;
+  private final SnsClient sns;
+  private final int retry;
+  private final long retryIntervalMs;
+
+  public SNSListener(String topicArn, SnsClient sns, int retry, long retryIntervalMs) {
+    this.sns = sns;
+    this.topicArn = topicArn;
+    this.retry = retry;
+    this.retryIntervalMs = retryIntervalMs;
+  }
+
+  @Override
+  public void notify(Object event) {
+    try {
+      String msg = EventParser.toJson(event);
+      PublishRequest request = PublishRequest.builder()
+              .message(msg)
+              .topicArn(topicArn)
+              .build();
+      Tasks.foreach(request)
+          .exponentialBackoff(retryIntervalMs, retryIntervalMs, retryIntervalMs, 1 /* scale factor */)
+          .retry(retry)
+          .onlyRetryOn(NotFoundException.class)

Review comment:
       This is done because when the topic is created, there might be a few seconds of inconsistency resulting in NotFoundException, such error is detected during tests. But I agree it seems like an issue that we should have a separated method to resolve, maybe directly have a wait method in tests.

##########
File path: aws/src/main/java/org/apache/iceberg/aws/AwsClientFactory.java
##########
@@ -56,6 +58,10 @@
    */
   DynamoDbClient dynamo();
 
+  SnsClient sns();

Review comment:
       good point, will add




-- 
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: issues-unsubscribe@iceberg.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org