-
Notifications
You must be signed in to change notification settings - Fork 119
[WIP][ISSUE #22]rocketmq-connect-redis adapt to the new connect api #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
doubleDimple
wants to merge
5
commits into
apache:master
Choose a base branch
from
doubleDimple:support_redis_connent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...t-redis/src/main/java/org/apache/rocketmq/connect/redis/connector/RedisSinkConnector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * 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.rocketmq.connect.redis.connector; | ||
|
|
||
| import io.openmessaging.KeyValue; | ||
| import io.openmessaging.connector.api.Task; | ||
| import io.openmessaging.connector.api.sink.SinkConnector; | ||
| import org.apache.rocketmq.connect.redis.config.Config; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * author: doubleDimple | ||
| */ | ||
| public class RedisSinkConnector extends SinkConnector { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(RedisSinkConnector.class); | ||
|
|
||
| private volatile boolean configValid = false; | ||
| private volatile boolean adminStarted; | ||
| private KeyValue keyValue; | ||
|
|
||
| @Override | ||
| public String verifyAndSetConfig(KeyValue config) { | ||
| this.keyValue = config; | ||
| String msg = Config.checkConfig(keyValue); | ||
| if (msg != null) { | ||
| return msg; | ||
| } | ||
| this.configValid = true; | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void start() { | ||
| LOGGER.info("the redisSinkConnector is start..."); | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void pause() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void resume() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Task> taskClass() { | ||
| return RedisSinkTask.class; | ||
| } | ||
|
|
||
| @Override | ||
| public List<KeyValue> taskConfigs() { | ||
| List<KeyValue> keyValues = new ArrayList<>(); | ||
| keyValues.add(this.keyValue); | ||
| return keyValues; | ||
| } | ||
| } |
155 changes: 155 additions & 0 deletions
155
...onnect-redis/src/main/java/org/apache/rocketmq/connect/redis/connector/RedisSinkTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| * 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.rocketmq.connect.redis.connector; | ||
|
|
||
| import com.alibaba.fastjson.JSONObject; | ||
| import io.openmessaging.KeyValue; | ||
| import io.openmessaging.connector.api.common.QueueMetaData; | ||
| import io.openmessaging.connector.api.data.EntryType; | ||
| import io.openmessaging.connector.api.data.Field; | ||
| import io.openmessaging.connector.api.data.Schema; | ||
| import io.openmessaging.connector.api.data.SinkDataEntry; | ||
| import io.openmessaging.connector.api.sink.SinkTask; | ||
| import org.apache.rocketmq.connect.redis.config.Config; | ||
| import org.apache.rocketmq.connect.redis.converter.KVEntryConverter; | ||
| import org.apache.rocketmq.connect.redis.converter.RedisEntryConverter; | ||
| import org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler; | ||
| import org.apache.rocketmq.connect.redis.handler.RedisEventHandler; | ||
| import org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor; | ||
| import org.apache.rocketmq.connect.redis.processor.RedisEventProcessor; | ||
| import org.apache.rocketmq.connect.redis.sink.RedisUpdater; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * author doubleDimple | ||
| */ | ||
| public class RedisSinkTask extends SinkTask { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(RedisSinkTask.class); | ||
|
|
||
| private RedisUpdater updater; | ||
|
|
||
| /** | ||
| * listening and handle Redis event. | ||
| */ | ||
| private RedisEventProcessor eventProcessor; | ||
| private Config config; | ||
| /** | ||
| * convert kVEntry to list of sourceDataEntry | ||
| */ | ||
| private KVEntryConverter kvEntryConverter; | ||
|
|
||
| public RedisEventProcessor getEventProcessor() { | ||
| return eventProcessor; | ||
| } | ||
|
|
||
| public void setEventProcessor(RedisEventProcessor eventProcessor) { | ||
| this.eventProcessor = eventProcessor; | ||
| } | ||
|
|
||
| public Config getConfig() { | ||
| return config; | ||
| } | ||
|
|
||
| @Override | ||
| public void put(Collection<SinkDataEntry> sinkDataEntries) { | ||
| //save data from MQ to redis | ||
| for (SinkDataEntry sinkDataEntry : sinkDataEntries) { | ||
| Map<Field, Object[]> fieldMap = new HashMap<>(); | ||
| Object[] payloads = sinkDataEntry.getPayload(); | ||
|
|
||
| Schema schema = sinkDataEntry.getSchema(); | ||
| EntryType entryType = sinkDataEntry.getEntryType(); | ||
|
|
||
| List<Field> fields = schema.getFields(); | ||
| Boolean parseError = false; | ||
| if (!fields.isEmpty()) { | ||
| for (Field field : fields) { | ||
| Object fieldValue = payloads[field.getIndex()]; | ||
| Object[] value = JSONObject.parseArray((String)fieldValue).toArray(); | ||
| if (value.length == 2) { | ||
| fieldMap.put(field, value); | ||
| } else { | ||
| LOGGER.error("parseArray error, fieldValue:{}", fieldValue); | ||
| parseError = true; | ||
| } | ||
| } | ||
| } | ||
| if (!parseError) { | ||
| Boolean isSuccess = updater.push(fieldMap, entryType); | ||
| if (!isSuccess) { | ||
| LOGGER.error("push data error, entryType:{}, fieldMap:{}", fieldMap, entryType); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void commit(Map<QueueMetaData, Long> offsets) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void start(KeyValue keyValue) { | ||
| this.kvEntryConverter = new RedisEntryConverter(); | ||
|
|
||
| this.config = new Config(); | ||
| this.config.load(keyValue); | ||
| LOGGER.info("task config msg: {}", this.config.toString()); | ||
|
|
||
| this.eventProcessor = new DefaultRedisEventProcessor(config); | ||
| RedisEventHandler eventHandler = new DefaultRedisEventHandler(this.config); | ||
| this.eventProcessor.registEventHandler(eventHandler); | ||
| try { | ||
| this.eventProcessor.start(); | ||
| LOGGER.info("Redis task start."); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| LOGGER.error("processor start error: [{}]", e.getMessage()); | ||
| this.stop(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| if (this.eventProcessor != null) { | ||
| try { | ||
| this.eventProcessor.stop(); | ||
| LOGGER.info("Redis task is stopped."); | ||
| } catch (IOException e) { | ||
| LOGGER.error("processor stop error: {}", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void pause() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void resume() { | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...etmq-connect-redis/src/main/java/org/apache/rocketmq/connect/redis/sink/RedisUpdater.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.apache.rocketmq.connect.redis.sink; | ||
|
|
||
| import io.openmessaging.connector.api.data.EntryType; | ||
| import io.openmessaging.connector.api.data.Field; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class RedisUpdater { | ||
|
|
||
|
|
||
| public Boolean push(Map<Field, Object[]> fieldMap, EntryType entryType) { | ||
|
|
||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Large diff (752 lines). Consider breaking into smaller, focused PRs for easier review.