You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/02/21 05:52:53 UTC
[GitHub] [incubator-seatunnel] leo65535 opened a new pull request #1296: [Feature][connector] Add flink socket connector based on table api
leo65535 opened a new pull request #1296:
URL: https://github.com/apache/incubator-seatunnel/pull/1296
<!--
Thank you for contributing to SeaTunnel! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
## Contribution Checklist
- Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
- Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
- Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
-->
## Purpose of this pull request
<!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
Add flink socket connector based on table api.
```
SET 'table.dml-sync' = 'true';
CREATE TABLE UserScores (
name STRING,
score INT
) WITH (
'connector' = 'seatunnel-socket',
'format'='csv'
);
CREATE TABLE print_table (
name STRING,
score INT
) WITH (
'connector' = 'print',
'sink.parallelism' = '1'
);
INSERT INTO print_table SELECT * FROM events where score = 1;
```
## Check list
* [ ] Code changed are covered with tests, or it does not need tests for reason:
* [ ] If any new Jar binary package adding in you PR, please add License Notice according
[New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/developement/NewLicenseGuide.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] asdf2014 commented on a change in pull request #1296: [Feature][connector] Add flink socket connector based on table api
Posted by GitBox <gi...@apache.org>.
asdf2014 commented on a change in pull request #1296:
URL: https://github.com/apache/incubator-seatunnel/pull/1296#discussion_r813000653
##########
File path: seatunnel-connectors/seatunnel-connector-flink-socket/src/main/java/org/apache/seatunnel/flink/connector/socket/source/SocketSourceFunction.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.flink.connector.socket.source;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.RuntimeContextInitializationContextAdapters;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
+import org.apache.flink.table.data.RowData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+/**
+ * The {@link SocketSourceFunction} opens a socket and consumes bytes.
+ *
+ * <p>It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to
+ * a pluggable {@link DeserializationSchema}.
+ *
+ * <p>Note: This is only an example and should not be used in production. The source function is not
+ * fault-tolerant and can only work with a parallelism of 1.
+ */
+public final class SocketSourceFunction extends RichSourceFunction<RowData>
+ implements ResultTypeQueryable<RowData> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SocketSourceFunction.class);
+
+ private final String hostname;
+ private final int port;
+ private final byte byteDelimiter;
+ private final DeserializationSchema<RowData> deserializer;
+ private static final int WAIT_TIME = 1000;
+
+ private volatile boolean isRunning = true;
+ private Socket currentSocket;
Review comment:
It is not recommended to use the Socket filed that cannot be serialized in the Serializable class
##########
File path: seatunnel-connectors/seatunnel-connector-flink-socket/src/main/java/org/apache/seatunnel/flink/connector/socket/source/SocketSourceFunction.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.flink.connector.socket.source;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.RuntimeContextInitializationContextAdapters;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
+import org.apache.flink.table.data.RowData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+/**
+ * The {@link SocketSourceFunction} opens a socket and consumes bytes.
+ *
+ * <p>It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to
+ * a pluggable {@link DeserializationSchema}.
+ *
+ * <p>Note: This is only an example and should not be used in production. The source function is not
+ * fault-tolerant and can only work with a parallelism of 1.
+ */
+public final class SocketSourceFunction extends RichSourceFunction<RowData>
+ implements ResultTypeQueryable<RowData> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SocketSourceFunction.class);
+
+ private final String hostname;
+ private final int port;
+ private final byte byteDelimiter;
+ private final DeserializationSchema<RowData> deserializer;
+ private static final int WAIT_TIME = 1000;
+
+ private volatile boolean isRunning = true;
+ private Socket currentSocket;
+
+ public SocketSourceFunction(
+ String hostname,
+ int port,
+ byte byteDelimiter,
+ DeserializationSchema<RowData> deserializer) {
+ this.hostname = hostname;
+ this.port = port;
+ this.byteDelimiter = byteDelimiter;
+ this.deserializer = deserializer;
+ }
+
+ @Override
+ public TypeInformation<RowData> getProducedType() {
+ return deserializer.getProducedType();
+ }
+
+ @Override
+ public void open(Configuration parameters) throws Exception {
+ deserializer.open(
+ RuntimeContextInitializationContextAdapters.deserializationAdapter(
+ getRuntimeContext()));
+ }
+
+ @Override
+ public void run(SourceContext<RowData> ctx) throws Exception {
+ while (isRunning) {
+ // open and consume from socket
+ try (final Socket socket = new Socket()) {
+ currentSocket = socket;
+ socket.connect(new InetSocketAddress(hostname, port), 0);
+ try (InputStream stream = socket.getInputStream()) {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ int b;
+ while ((b = stream.read()) >= 0) {
+ // buffer until delimiter
+ if (b != byteDelimiter) {
+ buffer.write(b);
+ }
+ // decode and emit record
+ else {
+ ctx.collect(deserializer.deserialize(buffer.toByteArray()));
+ buffer.reset();
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.warn("Meet exception when reading from socket", e);
+ }
+ Thread.sleep(WAIT_TIME);
+ }
+ }
+
+ @Override
+ public void cancel() {
+ isRunning = false;
+ try {
+ currentSocket.close();
+ } catch (Exception t) {
+ // ignore
Review comment:
Normally we rename the `t` as `ignored` instead of adding comment here
##########
File path: seatunnel-connectors/seatunnel-connector-flink-socket/src/main/java/org/apache/seatunnel/flink/connector/socket/source/SocketSourceFunction.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.flink.connector.socket.source;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.RuntimeContextInitializationContextAdapters;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
+import org.apache.flink.table.data.RowData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+/**
+ * The {@link SocketSourceFunction} opens a socket and consumes bytes.
+ *
+ * <p>It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to
+ * a pluggable {@link DeserializationSchema}.
+ *
+ * <p>Note: This is only an example and should not be used in production. The source function is not
+ * fault-tolerant and can only work with a parallelism of 1.
+ */
+public final class SocketSourceFunction extends RichSourceFunction<RowData>
Review comment:
Please add `serialVersionUID` field for this Serializable class
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] leo65535 commented on a change in pull request #1296: [Feature][connector] Add flink socket connector based on table api
Posted by GitBox <gi...@apache.org>.
leo65535 commented on a change in pull request #1296:
URL: https://github.com/apache/incubator-seatunnel/pull/1296#discussion_r816688721
##########
File path: seatunnel-connectors/seatunnel-connector-flink-socket/src/main/java/org/apache/seatunnel/flink/connector/socket/source/SocketSourceFunction.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.flink.connector.socket.source;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.RuntimeContextInitializationContextAdapters;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
+import org.apache.flink.table.data.RowData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+/**
+ * The {@link SocketSourceFunction} opens a socket and consumes bytes.
+ *
+ * <p>It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to
+ * a pluggable {@link DeserializationSchema}.
+ *
+ * <p>Note: This is only an example and should not be used in production. The source function is not
+ * fault-tolerant and can only work with a parallelism of 1.
+ */
+public final class SocketSourceFunction extends RichSourceFunction<RowData>
+ implements ResultTypeQueryable<RowData> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SocketSourceFunction.class);
+
+ private final String hostname;
+ private final int port;
+ private final byte byteDelimiter;
+ private final DeserializationSchema<RowData> deserializer;
+ private static final int WAIT_TIME = 1000;
+
+ private volatile boolean isRunning = true;
+ private Socket currentSocket;
Review comment:
We need define the variable here, and will use it in `cancel` method.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] leo65535 commented on a change in pull request #1296: [Feature][connector] Add flink socket connector based on table api
Posted by GitBox <gi...@apache.org>.
leo65535 commented on a change in pull request #1296:
URL: https://github.com/apache/incubator-seatunnel/pull/1296#discussion_r816687639
##########
File path: seatunnel-connectors/seatunnel-connector-flink-socket/src/main/java/org/apache/seatunnel/flink/connector/socket/source/SocketSourceFunction.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.flink.connector.socket.source;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.RuntimeContextInitializationContextAdapters;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
+import org.apache.flink.table.data.RowData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+/**
+ * The {@link SocketSourceFunction} opens a socket and consumes bytes.
+ *
+ * <p>It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to
+ * a pluggable {@link DeserializationSchema}.
+ *
+ * <p>Note: This is only an example and should not be used in production. The source function is not
+ * fault-tolerant and can only work with a parallelism of 1.
+ */
+public final class SocketSourceFunction extends RichSourceFunction<RowData>
+ implements ResultTypeQueryable<RowData> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SocketSourceFunction.class);
+
+ private final String hostname;
+ private final int port;
+ private final byte byteDelimiter;
+ private final DeserializationSchema<RowData> deserializer;
+ private static final int WAIT_TIME = 1000;
+
+ private volatile boolean isRunning = true;
+ private Socket currentSocket;
Review comment:
It seems a minor problem, do you have good practice if we don't use `Socket` here?
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] leo65535 commented on pull request #1296: [Feature][connector] Add flink socket connector based on table api
Posted by GitBox <gi...@apache.org>.
leo65535 commented on pull request #1296:
URL: https://github.com/apache/incubator-seatunnel/pull/1296#issuecomment-1055334376
Thanks for your review @asdf2014, patch has been updated.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] leo65535 commented on a change in pull request #1296: [Feature][connector] Add flink socket connector based on table api
Posted by GitBox <gi...@apache.org>.
leo65535 commented on a change in pull request #1296:
URL: https://github.com/apache/incubator-seatunnel/pull/1296#discussion_r816686544
##########
File path: seatunnel-connectors/seatunnel-connector-flink-socket/src/main/java/org/apache/seatunnel/flink/connector/socket/source/SocketSourceFunction.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.flink.connector.socket.source;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.RuntimeContextInitializationContextAdapters;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
+import org.apache.flink.table.data.RowData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+/**
+ * The {@link SocketSourceFunction} opens a socket and consumes bytes.
+ *
+ * <p>It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to
+ * a pluggable {@link DeserializationSchema}.
+ *
+ * <p>Note: This is only an example and should not be used in production. The source function is not
+ * fault-tolerant and can only work with a parallelism of 1.
+ */
+public final class SocketSourceFunction extends RichSourceFunction<RowData>
Review comment:
Done
##########
File path: seatunnel-connectors/seatunnel-connector-flink-socket/src/main/java/org/apache/seatunnel/flink/connector/socket/source/SocketSourceFunction.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.flink.connector.socket.source;
+
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.serialization.RuntimeContextInitializationContextAdapters;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
+import org.apache.flink.table.data.RowData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+/**
+ * The {@link SocketSourceFunction} opens a socket and consumes bytes.
+ *
+ * <p>It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to
+ * a pluggable {@link DeserializationSchema}.
+ *
+ * <p>Note: This is only an example and should not be used in production. The source function is not
+ * fault-tolerant and can only work with a parallelism of 1.
+ */
+public final class SocketSourceFunction extends RichSourceFunction<RowData>
+ implements ResultTypeQueryable<RowData> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SocketSourceFunction.class);
+
+ private final String hostname;
+ private final int port;
+ private final byte byteDelimiter;
+ private final DeserializationSchema<RowData> deserializer;
+ private static final int WAIT_TIME = 1000;
+
+ private volatile boolean isRunning = true;
+ private Socket currentSocket;
+
+ public SocketSourceFunction(
+ String hostname,
+ int port,
+ byte byteDelimiter,
+ DeserializationSchema<RowData> deserializer) {
+ this.hostname = hostname;
+ this.port = port;
+ this.byteDelimiter = byteDelimiter;
+ this.deserializer = deserializer;
+ }
+
+ @Override
+ public TypeInformation<RowData> getProducedType() {
+ return deserializer.getProducedType();
+ }
+
+ @Override
+ public void open(Configuration parameters) throws Exception {
+ deserializer.open(
+ RuntimeContextInitializationContextAdapters.deserializationAdapter(
+ getRuntimeContext()));
+ }
+
+ @Override
+ public void run(SourceContext<RowData> ctx) throws Exception {
+ while (isRunning) {
+ // open and consume from socket
+ try (final Socket socket = new Socket()) {
+ currentSocket = socket;
+ socket.connect(new InetSocketAddress(hostname, port), 0);
+ try (InputStream stream = socket.getInputStream()) {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ int b;
+ while ((b = stream.read()) >= 0) {
+ // buffer until delimiter
+ if (b != byteDelimiter) {
+ buffer.write(b);
+ }
+ // decode and emit record
+ else {
+ ctx.collect(deserializer.deserialize(buffer.toByteArray()));
+ buffer.reset();
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.warn("Meet exception when reading from socket", e);
+ }
+ Thread.sleep(WAIT_TIME);
+ }
+ }
+
+ @Override
+ public void cancel() {
+ isRunning = false;
+ try {
+ currentSocket.close();
+ } catch (Exception t) {
+ // ignore
Review comment:
Make sense, thanks.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] CalvinKirs commented on pull request #1296: [Feature][connector] Add flink socket connector based on table api
Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on pull request #1296:
URL: https://github.com/apache/incubator-seatunnel/pull/1296#issuecomment-1047003689
@SteNicholas hi PTAL.Thx
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org