TaoZex commented on code in PR #3312:
URL: 
https://github.com/apache/incubator-seatunnel/pull/3312#discussion_r1014791976


##########
seatunnel-connectors-v2/connector-rabbitmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rabbitmq/sink/RabbitmqSink.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.seatunnel.connectors.seatunnel.rabbitmq.sink;
+
+import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.sink.SeaTunnelSink;
+import org.apache.seatunnel.api.sink.SinkWriter;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSimpleSink;
+import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import 
org.apache.seatunnel.connectors.seatunnel.rabbitmq.config.RabbitmqConfig;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.auto.service.AutoService;
+
+import java.io.IOException;
+
+@AutoService(SeaTunnelSink.class)
+public class RabbitmqSink extends AbstractSimpleSink<SeaTunnelRow, Void> {
+    private SeaTunnelRowType seaTunnelRowType;
+    private Config pluginConfig;
+    private RabbitmqConfig rabbitMQConfig;
+
+    @Override
+    public String getPluginName() {
+        return "RabbitMQ";
+    }
+
+    @Override
+    public void prepare(Config pluginConfig) throws PrepareFailException {
+        this.pluginConfig = pluginConfig;
+        rabbitMQConfig = new RabbitmqConfig(pluginConfig);

Review Comment:
   Need parameter check.



##########
docs/en/connector-v2/source/Rabbitmq.md:
##########
@@ -0,0 +1,148 @@
+# Rabbitmq
+
+> Rabbitmq source connector
+
+## Description
+
+Used to read data from Rabbitmq.
+
+## Key features
+
+- [ ] [batch](../../concept/connector-v2-features.md)
+- [x] [stream](../../concept/connector-v2-features.md)
+- [x] [exactly-once](../../concept/connector-v2-features.md)
+- [x] [schema projection](../../concept/connector-v2-features.md)
+- [ ] [parallelism](../../concept/connector-v2-features.md)
+- [ ] [support user-defined split](../../concept/connector-v2-features.md)
+
+:::tip
+The source must be non-parallel (parallelism set to 1) in order to achieve 
exactly-once. This limitation is mainly due to RabbitMQ’s approach to 
dispatching messages from a single queue to multiple consumers.
+
+##  Options
+
+| name                        | type    | required | default value |
+|-----------------------------|---------|----------|---------------|
+| host                        | string  | yes      | -             |
+| port                        | int     | yes      | -             |
+| virtual_host                | string  | yes      | -             |
+| username                    | string  | yes      | -             |
+| password                    | string  | yes      | -             |
+| url                         | string  | no       | -             |
+| queue_name                  | string  | yes      | -             |

Review Comment:
   If queue_name is required,it should be in front of the url.



##########
seatunnel-connectors-v2/connector-rabbitmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rabbitmq/sink/RabbitmqSinkWriter.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.rabbitmq.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import 
org.apache.seatunnel.connectors.seatunnel.rabbitmq.client.RabbitmqClient;
+import 
org.apache.seatunnel.connectors.seatunnel.rabbitmq.config.RabbitmqConfig;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+public class RabbitmqSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> 
{
+    private static final Logger LOG = 
LoggerFactory.getLogger(RabbitmqSinkWriter.class);
+    private RabbitmqClient rabbitMQClient;
+    private final JsonSerializationSchema jsonSerializationSchema;
+
+    public RabbitmqSinkWriter(RabbitmqConfig config, SeaTunnelRowType 
seaTunnelRowType) {
+        this.rabbitMQClient = new RabbitmqClient(config);
+        this.jsonSerializationSchema = new 
JsonSerializationSchema(seaTunnelRowType);
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) {
+        rabbitMQClient.write(jsonSerializationSchema.serialize(element));
+    }
+
+    @Override
+    public Optional prepareCommit() {
+

Review Comment:
   Delete this line.



##########
seatunnel-connectors-v2/connector-rabbitmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rabbitmq/client/RabbitmqClient.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.rabbitmq.client;
+
+import org.apache.seatunnel.common.Handover;
+import 
org.apache.seatunnel.connectors.seatunnel.rabbitmq.config.RabbitmqConfig;
+
+import com.rabbitmq.client.Channel;
+import com.rabbitmq.client.Connection;
+import com.rabbitmq.client.ConnectionFactory;
+import com.rabbitmq.client.DefaultConsumer;
+import com.rabbitmq.client.Delivery;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.util.concurrent.TimeoutException;
+
+@Slf4j
+@AllArgsConstructor
+public class RabbitmqClient {
+    private RabbitmqConfig config;
+    private ConnectionFactory connectionFactory;
+    private Connection connection;
+    private Channel channel;
+
+    public RabbitmqClient(RabbitmqConfig config) {
+        this.config = config;
+        try {
+            this.connectionFactory = getConnectionFactory();
+            this.connection = connectionFactory.newConnection();
+            this.channel = connection.createChannel();
+            //set channel prefetch count
+            if (config.getPrefetchCount() != null) {
+                channel.basicQos(config.getPrefetchCount(), true);
+            }
+            setupQueue();
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Error while create RMQ client with "
+                            + this.config.getQueueName()
+                            + " at "
+                            + this.config.getHost(),
+                    e);
+        }

Review Comment:
   How about use Stringformat in RuntimeException?



##########
docs/en/connector-v2/sink/Rabbitmq.md:
##########
@@ -0,0 +1,95 @@
+# Rabbitmq
+
+> Rabbitmq sink connector
+
+## Description
+
+Used to write data to Rabbitmq.
+
+## Key features
+
+- [ ] [exactly-once](../../concept/connector-v2-features.md)
+- [ ] [schema projection](../../concept/connector-v2-features.md)
+
+##  Options
+
+| name                        | type    | required | default value |
+|-----------------------------|---------|----------|---------------|
+| host                        | string  | yes      | -             |
+| port                        | int     | yes      | -             |
+| virtual_host                | string  | yes      | -             |
+| username                    | string  | yes      | -             |
+| password                    | string  | yes      | -             |
+| url                         | string  | no       | -             |
+| queue_name                  | string  | yes      | -             |

Review Comment:
   Same as above.



##########
seatunnel-connectors-v2/connector-rabbitmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rabbitmq/config/RabbitmqConfig.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.rabbitmq.config;
+
+import org.apache.seatunnel.common.config.TypesafeConfigUtils;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.common.annotations.VisibleForTesting;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+@Setter
+@Getter
+@AllArgsConstructor
+public class RabbitmqConfig implements Serializable {
+    public static final String HOST = "host";
+    public static final String PORT = "port";
+    public static final String VIRTUAL_HOST = "virtual_host";
+    public static final String USERNAME = "username";
+    public static final String PASSWORD = "password";
+    public static final String URL = "url";
+    public static final String NETWORK_RECOVERY_INTERVAL = 
"network_recovery_interval";
+    public static final String AUTOMATIC_RECOVERY_ENABLED = 
"automatic_recovery_enabled";
+    public static final String TOPOLOGY_RECOVERY_ENABLED = 
"topology_recovery_enabled";
+    public static final String CONNECTION_TIMEOUT = "connection_timeout";
+    public static final String REQUESTED_CHANNEL_MAX = "requested_channel_max";
+    public static final String REQUESTED_FRAME_MAX = "requested_frame_max";
+    public static final String REQUESTED_HEARTBEAT = "requested_heartbeat";
+
+    public static final String PREFETCH_COUNT = "prefetch_count";
+    public static final String DELIVERY_TIMEOUT = "delivery_timeout";
+    public static final String QUEUE_NAME = "queue_name";
+    public static final String ROUTING_KEY = "routing_key";
+    public static final String EXCHANGE = "exchange";
+
+
+    public static final String LOG_FAILURES_ONLY = "log_failures_only";
+
+    private String host;
+    private Integer port;
+    private String virtualHost;
+    private String username;
+    private String password;
+    private String uri;
+    private Integer networkRecoveryInterval;

Review Comment:
   int is more efficient than Integer in serialization.



##########
seatunnel-connectors-v2/connector-rabbitmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rabbitmq/source/RabbitmqSource.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.seatunnel.connectors.seatunnel.rabbitmq.source;
+
+import org.apache.seatunnel.api.common.JobContext;
+import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Boundedness;
+import org.apache.seatunnel.api.source.SeaTunnelSource;
+import org.apache.seatunnel.api.source.SourceReader;
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.constants.JobMode;
+import org.apache.seatunnel.connectors.seatunnel.common.schema.SeaTunnelSchema;
+import 
org.apache.seatunnel.connectors.seatunnel.rabbitmq.config.RabbitmqConfig;
+import org.apache.seatunnel.connectors.seatunnel.rabbitmq.split.RabbitmqSplit;
+import 
org.apache.seatunnel.connectors.seatunnel.rabbitmq.split.RabbitmqSplitEnumeratorState;
+import org.apache.seatunnel.format.json.JsonDeserializationSchema;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.auto.service.AutoService;
+
+@AutoService(SeaTunnelSource.class)
+public class RabbitmqSource implements SeaTunnelSource<SeaTunnelRow, 
RabbitmqSplit, RabbitmqSplitEnumeratorState> {
+
+    private DeserializationSchema<SeaTunnelRow> deserializationSchema;
+    private JobContext jobContext;
+    private RabbitmqConfig rabbitMQConfig;
+
+    @Override
+    public Boundedness getBoundedness() {
+        return JobMode.BATCH.equals(jobContext.getJobMode()) ? 
Boundedness.BOUNDED : Boundedness.UNBOUNDED;
+    }
+
+    @Override
+    public String getPluginName() {
+        return "RabbitMQ";
+    }
+
+    @Override
+    public void prepare(Config config) throws PrepareFailException {
+        this.rabbitMQConfig = new RabbitmqConfig(config);

Review Comment:
   Same as above.



##########
seatunnel-connectors-v2/connector-rabbitmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rabbitmq/sink/RabbitmqSinkWriter.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.rabbitmq.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import 
org.apache.seatunnel.connectors.seatunnel.rabbitmq.client.RabbitmqClient;
+import 
org.apache.seatunnel.connectors.seatunnel.rabbitmq.config.RabbitmqConfig;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+public class RabbitmqSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> 
{
+    private static final Logger LOG = 
LoggerFactory.getLogger(RabbitmqSinkWriter.class);

Review Comment:
   Use @Sl4j?



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

Reply via email to