Skip to content

Commit

Permalink
[ISSUE apache#367] Refactor connector
Browse files Browse the repository at this point in the history
    1.support load plugin from eventMeshPluginDir
    2.remove connector plugin from runtime
  • Loading branch information
ruanwenjun committed Jul 16, 2021
1 parent ed446ba commit 16653b7
Show file tree
Hide file tree
Showing 48 changed files with 415 additions and 231 deletions.
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
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
36 changes: 36 additions & 0 deletions eventmesh-connector-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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"
}
}
copy {
into '../dist/plugin/connector'
from "../eventmesh-connector-plugin/dist/apps/eventmesh-connector-rocketmq-${version}.jar"
}
}
}
File renamed without changes.
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 @@ -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.

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
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
package org.apache.eventmesh.runtime.core.plugin;

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

import io.openmessaging.api.Message;
import io.openmessaging.api.SendCallback;

import org.apache.eventmesh.api.RRCallback;
import org.apache.eventmesh.api.factory.ConnectorPluginFactory;
import org.apache.eventmesh.api.producer.MeshMQProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -35,7 +35,7 @@ public class MQProducerWrapper extends MQWrapper {
protected MeshMQProducer meshMQProducer;

public MQProducerWrapper(String connectorPluginType) {
this.meshMQProducer = PluginFactory.getMeshMQProducer(connectorPluginType);
this.meshMQProducer = ConnectorPluginFactory.getMeshMQProducer(connectorPluginType);
if (meshMQProducer == null) {
logger.error("can't load the meshMQProducer plugin, please check.");
throw new RuntimeException("doesn't load the meshMQProducer plugin, please check.");
Expand All @@ -47,24 +47,10 @@ public synchronized void init(Properties keyValue) throws Exception {
return;
}

meshMQProducer = getSpiMeshMQProducer();
if (meshMQProducer == null) {
logger.error("can't load the meshMQProducer plugin, please check.");
throw new RuntimeException("doesn't load the meshMQProducer plugin, please check.");
}

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

private MeshMQProducer getSpiMeshMQProducer() {
ServiceLoader<MeshMQProducer> meshMQProducerServiceLoader = ServiceLoader.load(MeshMQProducer.class);
if (meshMQProducerServiceLoader.iterator().hasNext()) {
return meshMQProducerServiceLoader.iterator().next();
}
return null;
}

public synchronized void start() throws Exception {
if (started.get()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.apache.eventmesh.runtime.constants.EventMeshConstants;
import org.apache.eventmesh.runtime.core.plugin.MQConsumerWrapper;
import org.apache.eventmesh.runtime.core.plugin.MQProducerWrapper;
import org.apache.eventmesh.runtime.core.plugin.PluginFactory;
import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.dispatch.DownstreamDispatchStrategy;
import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session;
import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push.DownStreamMsgContext;
Expand Down
Loading

0 comments on commit 16653b7

Please sign in to comment.