Skip to content
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

[ISSUE #367] Refactor connector #433

Merged
merged 3 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 1 addition & 47 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -188,45 +188,6 @@ subprojects {
}
}

// checkstyle {
// toolVersion = "8.32"
// ignoreFailures = true
// sourceSets = [sourceSets.main]
// configFile = '../style/codeStyle.xml' as File
// showViolations true
// }
//
// tasks.withType(Checkstyle) {
// reports {
// xml.enabled false
// html.enabled true
// }
// }
//
// sourceSets {
// main {
// java {
// srcDir 'src/main/java'
// }
//
// resources {
// srcDir 'src/main/resources'
// }
//
// }
//
// test {
// java {
// srcDir 'src/test/java'
// }
//
// resources {
// srcDir 'src/test/resources'
// }
//
// }
// }

spotbugs {
//toolVersion = '4.2.3'
ignoreFailures = true
Expand Down Expand Up @@ -271,14 +232,6 @@ subprojects {
}
}

// tasks.withType(Pmd) {
// reports {
// xml.enabled = false
// html.enabled = true
// }
// }


pmd {
consoleOutput = true
toolVersion = "6.23.0"
Expand Down Expand Up @@ -314,6 +267,7 @@ subprojects {
from project.jar.getArchivePath()
exclude 'eventmesh-common*.jar'
exclude 'eventmesh-connector-api*.jar'
exclude 'eventmesh-connector-plugin*.jar'
exclude 'eventmesh-starter*.jar'
exclude 'eventmesh-test*.jar'
exclude 'eventmesh-sdk*.jar'
Expand Down
14 changes: 10 additions & 4 deletions docs/cn/instructions/eventmesh-runtime-quickstart.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gradle至少为7.0, 推荐 7.0.*
```$ xslt
unzip EventMesh-master.zip
cd / *您的部署路径* /EventMesh-master
gradle clean dist tar -x test
gradle clean dist copyConnectorPlugin tar -x test
```

您将在目录/ *您的部署路径* /EventMesh-master/eventmesh-runtime/dist中获得**eventmesh-runtime_1.0.0.tar.gz**
Expand Down Expand Up @@ -57,14 +57,20 @@ sh start.sh
![project-structure](../../images/project-structure.png)

- eventmesh-common : eventmesh公共类与方法模块
- eventmesh-connector-api : eventmesh插件接口定义模块
- eventmesh-connector-rocketmq : eventmesh rocketmq插件模块
- eventmesh-connector-api : eventmesh connector插件接口定义模块
- eventmesh-connector-plugin : eventmesh connector插件模块
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventmesh-connector-api was moved into eventmesh-connector-plugin,the description and picture are not updated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will submit a pr to fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will submit a pr to fix.

See #323 , i want to let the student to fix it :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

- eventmesh-runtime : eventmesh运行时模块
- eventmesh-sdk-java : eventmesh java客户端sdk
- eventmesh-starter : eventmesh本地启动运行项目入口
- eventmesh-spi : eventmesh SPI加载模块

> 注:插件模块遵循eventmesh定义的spi机制,需要在对应模块中的/main/resources/META-INF/eventmesh 下配置相关接口与实现类的映射文件
> 注:插件模块遵循eventmesh定义的SPI规范, 自定义的SPI接口需要使用注解@EventMeshSPI标识.
> 插件实例需要在对应模块中的/main/resources/META-INF/eventmesh 下配置相关接口与实现类的映射文件,文件名为SPI接口全类名.
> 文件内容为插件实例名到插件实例的映射, 具体可以参考eventmesh-connector-rocketmq插件模块

插件可以从classpath和插件目录下面加载. 在本地开发阶段可以将使用的插件在eventmesh-starter模块build.gradle中进行声明,或者执行gradle的copyConnectorPlugin任务
将插件拷贝至dist/plugin目录下, eventmesh默认会加载项目下dist/plugin目录下的插件, 加载目录可以通过-DeventMeshPluginDir=your_plugin_directory来改变插件目录.
运行时需要使用的插件实例可以在eventmesh.properties中进行配置

**2.3.2 配置插件**

Expand Down
16 changes: 12 additions & 4 deletions docs/en/instructions/eventmesh-runtime-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You will get **EventMesh-master.zip**
```$xslt
unzip EventMesh-master.zip
cd /*YOUR DEPLOY PATH*/EventMesh-master
gradle clean dist tar -x test
gradle clean dist copyConnectorPlugin tar -x test
```

You will get **EventMesh_1.2.0.tar.gz** in directory /* YOUR DEPLOY PATH */EventMesh-master/build
Expand Down Expand Up @@ -58,14 +58,22 @@ Same with 1.2

- eventmesh-common : eventmesh common classes and method module
- eventmesh-connector-api : eventmesh connector api definition module
- eventmesh-connector-rocketmq : eventmesh rocketmq connector module
- eventmesh-connector-plugin : eventmesh connector plugin instance module
- eventmesh-runtime : eventmesh runtime module
- eventmesh-sdk-java : eventmesh java client sdk
- eventmesh-starter : eventmesh project local start entry
- eventmesh-spi : eventmesh SPI load module

> ps: The loading of connector plugin follows the eventmesh SPI mechanism, it's necessary to configure the mapping file of
related interface and implementation class under /main/resources/meta-inf/eventmesh in the corresponding module
> ps: The plugin module follows the eventmesh SPI specification, custom SPI interface need to be identified with the @EventMeshSPI annotation.
> The plugin instance needs to be configured in corresponding module under /main/resources/meta-inf/eventmesh with the mapping file of
> related interface and implementation class. The content of the file is a mapping of plugin instance name to plugin instance, you can find more
> detail in eventmesh-connector-rocketmq module

The plugin can be loaded from classpath and plugin directory. In local develop, you can declare the used plugins in build.gradle of eventmesh-starter module,
or execute copyConnectorPlugin task of gradle to copy the plugin instance jar to dist/plugin directory. By default, eventmesh will load the plugins in project's
dist/plugin, this can be changed by add -DeventMeshPluginDir=your_plugin_directory.
The plugin instance need to be used at runtime can be configured in eventmesh.properties.


**2.3.2 Configure plugin**

Expand Down
Binary file modified docs/images/project-structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions eventmesh-connector-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.
*/

task copyConnectorPlugin(dependsOn: ['jar']) {
doFirst {
new File(projectDir, '../eventmesh-connector-plugin/dist/apps').mkdir()
new File(projectDir, '../dist/plugin/connector').mkdirs()
}
doLast {
copy {
into('../eventmesh-connector-plugin/dist/apps/')
from project.jar.getArchivePath()
exclude {
"eventmesh-connector-plugin-${version}.jar"
"eventmesh-connector-api-${version}.jar"
}
}
copy {
into '../dist/plugin/connector'
from "../eventmesh-connector-plugin/dist/apps/eventmesh-connector-rocketmq-${version}.jar"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ List open_message = [
]

dependencies {
implementation open_message,project(":eventmesh-common"), project(":eventmesh-spi")
api open_message, project(":eventmesh-common"), project(":eventmesh-spi")
testImplementation open_message,project(":eventmesh-common"), project(":eventmesh-spi")
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,33 @@
* under the License.
*/

package org.apache.eventmesh.runtime.core.plugin;
package org.apache.eventmesh.api.factory;

import org.apache.eventmesh.api.consumer.MeshMQPushConsumer;
import org.apache.eventmesh.api.producer.MeshMQProducer;
import org.apache.eventmesh.spi.EventMeshExtensionFactory;

public class PluginFactory {
/**
* The factory to get connector {@link MeshMQProducer} and {@link MeshMQPushConsumer}
*/
public class ConnectorPluginFactory {

/**
* Get MeshMQProducer instance by plugin name
*
* @param connectorPluginName plugin name
* @return MeshMQProducer instance
*/
public static MeshMQProducer getMeshMQProducer(String connectorPluginName) {
return EventMeshExtensionFactory.getExtension(MeshMQProducer.class, connectorPluginName);
}

/**
* Get MeshMQPushConsumer instance by plugin name
*
* @param connectorPluginName plugin name
* @return MeshMQPushConsumer instance
*/
public static MeshMQPushConsumer getMeshMQPushConsumer(String connectorPluginName) {
return EventMeshExtensionFactory.getExtension(MeshMQPushConsumer.class, connectorPluginName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ List open_message = [
]

dependencies {
implementation rocketmq, metrics,open_message,project(":eventmesh-connector-api"),project(":eventmesh-common")
testImplementation rocketmq, metrics,open_message,project(":eventmesh-connector-api"),project(":eventmesh-common")
api rocketmq, metrics, open_message, project(":eventmesh-connector-plugin:eventmesh-connector-api")
testImplementation rocketmq, metrics, open_message, project(":eventmesh-connector-plugin:eventmesh-connector-api")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.rocketmq.client.impl.consumer;
package org.apache.eventmesh.connector.rocketmq.client.impl.consumer;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -38,6 +38,9 @@
import org.apache.rocketmq.client.consumer.listener.ConsumeReturnType;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.hook.ConsumeMessageContext;
import org.apache.rocketmq.client.impl.consumer.ConsumeMessageService;
import org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl;
import org.apache.rocketmq.client.impl.consumer.ProcessQueue;
import org.apache.rocketmq.client.log.ClientLogger;
import org.apache.rocketmq.client.stat.ConsumerStatsManager;
import org.apache.rocketmq.common.MixAll;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ private void load() {
public String getProp(String key) {
return StringUtils.isEmpty(key) ? null : properties.getProperty(key, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.apache.eventmesh.connector.rocketmq.config.ConfigurationWrapper;
import org.apache.eventmesh.connector.rocketmq.patch.EventMeshConsumeConcurrentlyContext;
import org.apache.eventmesh.connector.rocketmq.utils.OMSUtil;
import org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService;
import org.apache.eventmesh.connector.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService;
import org.apache.rocketmq.client.impl.consumer.ConsumeMessageService;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Collections;
import java.util.Properties;

import io.openmessaging.api.Action;
import io.openmessaging.api.AsyncConsumeContext;
import io.openmessaging.api.AsyncMessageListener;
import io.openmessaging.api.Consumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#
# 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.
Expand All @@ -12,5 +13,9 @@
# 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.

org.apache.eventmesh.connector.rocketmq.consumer.RocketMQConsumerImpl
#
group=org.apache.eventmesh
version=1.2.0-SNAPSHOT
jdk=1.8
mavenUserName=
mavenPassword=

This file was deleted.

4 changes: 2 additions & 2 deletions eventmesh-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ List open_message = [


dependencies {
implementation metrics, open_message,project(":eventmesh-connector-api"),project(":eventmesh-common"),project(":eventmesh-spi")
testImplementation metrics,open_message,project(":eventmesh-common"),project(":eventmesh-connector-api"),project(":eventmesh-spi")
implementation metrics, open_message, project(":eventmesh-connector-plugin:eventmesh-connector-api")
testImplementation metrics, open_message, project(":eventmesh-connector-plugin:eventmesh-connector-api")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import java.util.List;
import java.util.Properties;
import java.util.ServiceLoader;

import io.openmessaging.api.AsyncMessageListener;
import io.openmessaging.api.Message;

import org.apache.eventmesh.api.AbstractContext;
import org.apache.eventmesh.api.consumer.MeshMQPushConsumer;
import org.apache.eventmesh.api.factory.ConnectorPluginFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,7 +36,7 @@ public class MQConsumerWrapper extends MQWrapper {
protected MeshMQPushConsumer meshMQPushConsumer;

public MQConsumerWrapper(String connectorPluginType) {
this.meshMQPushConsumer = PluginFactory.getMeshMQPushConsumer(connectorPluginType);
this.meshMQPushConsumer = ConnectorPluginFactory.getMeshMQPushConsumer(connectorPluginType);
if (meshMQPushConsumer == null) {
logger.error("can't load the meshMQPushConsumer plugin, please check.");
throw new RuntimeException("doesn't load the meshMQPushConsumer plugin, please check.");
Expand All @@ -52,24 +52,11 @@ public void unsubscribe(String topic) throws Exception {
}

public synchronized void init(Properties keyValue) throws Exception {
meshMQPushConsumer = getMeshMQPushConsumer();
if (meshMQPushConsumer == null) {
logger.error("can't load the meshMQPushConsumer plugin, please check.");
throw new RuntimeException("doesn't load the meshMQPushConsumer plugin, please check.");
}

meshMQPushConsumer.init(keyValue);
inited.compareAndSet(false, true);
}

private MeshMQPushConsumer getMeshMQPushConsumer() {
ServiceLoader<MeshMQPushConsumer> meshMQPushConsumerServiceLoader = ServiceLoader.load(MeshMQPushConsumer.class);
if (meshMQPushConsumerServiceLoader.iterator().hasNext()) {
return meshMQPushConsumerServiceLoader.iterator().next();
}
return null;
}

public synchronized void start() throws Exception {
meshMQPushConsumer.start();
started.compareAndSet(false, true);
Expand Down
Loading