Messaged
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# Service组件
|
||||
Service是Redkale最核心的组件,主要处理业务逻辑和操作数据层。Service实例分两种模式: <b>本地模式</b>和<b>远程模式</b>。其模式由```conf/application.xml```文件来配置。开发人员在调用过程中通常不需要区分Service实例是哪种模式。 <br/>
|
||||
并不是Sevice都能进行本地和远程模式切换, 以下情况的Service不能转成远程模式:
|
||||
* Service类修饰为```final```
|
||||
* Service类被标记```@Local```
|
||||
* Service类被标记```@Component```
|
||||
>Service是Redkale最核心的组件,主要处理业务逻辑和操作数据层。Service实例分两种模式: <b>本地模式</b>和<b>远程模式</b>。其模式由```conf/application.xml```文件来配置。开发人员在调用过程中通常不需要区分Service实例是哪种模式。 <br/>
|
||||
>并不是Sevice都能进行本地和远程模式切换, 以下情况的Service不能转成远程模式:
|
||||
1、Service类修饰为```final``` <br>
|
||||
2、Service类被标记```@Local``` <br>
|
||||
3、Service类被标记```@Component``` <br>
|
||||
|
||||
Redkale进程启动时扫描可加载的Service实现类,根据配置文件配置的模式采用```ASM```技术动态生成相应的Service临时类进行实例化,并注册到ResourceFactory同其他Service、Servlet依赖注入。
|
||||
37
src/main/java/org/redkale/mq/Messaged.java
Normal file
37
src/main/java/org/redkale/mq/Messaged.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.mq;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import java.lang.annotation.Retention;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.annotation.Target;
|
||||
import org.redkale.convert.ConvertType;
|
||||
|
||||
/**
|
||||
* MQ资源注解, 只能标记在Service类方法上
|
||||
* 1、方法必须是protected/public
|
||||
* 2、方法不能是final
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
@Documented
|
||||
@Target({METHOD})
|
||||
@Retention(RUNTIME)
|
||||
public @interface Messaged {
|
||||
|
||||
String mq() default "";
|
||||
|
||||
String group() default "";
|
||||
|
||||
String[] topics();
|
||||
|
||||
ConvertType convertType() default ConvertType.JSON;
|
||||
}
|
||||
@@ -218,7 +218,7 @@ public abstract class MessageAgent implements MessageManager {
|
||||
if (this.timeoutExecutor != null) {
|
||||
this.timeoutExecutor.shutdownNow();
|
||||
}
|
||||
if (this.workExecutor != null && this.workExecutor != application.getWorkExecutor()) {
|
||||
if (this.workExecutor != application.getWorkExecutor()) {
|
||||
this.workExecutor.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -400,12 +400,15 @@ public abstract class MessageAgent implements MessageManager {
|
||||
public abstract void onResourceChange(ResourceEvent[] events);
|
||||
|
||||
//
|
||||
@Override
|
||||
public abstract boolean createTopic(String... topics);
|
||||
|
||||
//删除topic,如果不存在则跳过
|
||||
@Override
|
||||
public abstract boolean deleteTopic(String... topics);
|
||||
|
||||
//查询所有topic
|
||||
@Override
|
||||
public abstract List<String> queryTopic();
|
||||
|
||||
//ServiceLoader时判断配置是否符合当前实现类
|
||||
|
||||
@@ -85,11 +85,6 @@ public abstract class Sncp {
|
||||
continue;
|
||||
}
|
||||
if (method.getAnnotation(Scheduled.class) != null) {
|
||||
if (Modifier.isStatic(method.getModifiers())
|
||||
|| method.getParameterCount() > 0) {
|
||||
throw new SncpException(Scheduled.class.getSimpleName() + " must be on protected and non-parameter method, but on " + method);
|
||||
}
|
||||
RedkaleClassLoader.putReflectionMethod(serviceTypeOrImplClass.getName(), method);
|
||||
continue;
|
||||
}
|
||||
if (Modifier.isStatic(method.getModifiers())) {
|
||||
|
||||
@@ -88,6 +88,8 @@ public interface Invoker<C, R> {
|
||||
returnDesc = Type.getDescriptor(Long.class);
|
||||
} else if (returnType == double.class) {
|
||||
returnDesc = Type.getDescriptor(Double.class);
|
||||
} else if (returnType == void.class) {
|
||||
returnDesc = Type.getDescriptor(Void.class);
|
||||
}
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
StringBuilder sbpts = new StringBuilder();
|
||||
@@ -144,7 +146,11 @@ public interface Invoker<C, R> {
|
||||
}
|
||||
|
||||
mv.visitMethodInsn(staticFlag ? INVOKESTATIC : (clazz.isInterface() ? INVOKEINTERFACE : INVOKEVIRTUAL), interName, method.getName(), "(" + paramDescs + ")" + returnPrimiveDesc, !staticFlag && clazz.isInterface());
|
||||
Asms.visitPrimitiveValueOf(mv, returnType);
|
||||
if (returnType == void.class) {
|
||||
mv.visitInsn(ACONST_NULL);
|
||||
} else {
|
||||
Asms.visitPrimitiveValueOf(mv, returnType);
|
||||
}
|
||||
mv.visitLabel(label1);
|
||||
mv.visitInsn(ARETURN);
|
||||
if (throwFlag) {
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
*/
|
||||
package org.redkale.test.util;
|
||||
|
||||
import org.redkale.util.Invoker;
|
||||
import java.io.IOException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.util.Invoker;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -15,6 +16,17 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
public class InvokerTest {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
InvokerTest test = new InvokerTest();
|
||||
test.run1();
|
||||
test.run2();
|
||||
test.run3();
|
||||
test.run4();
|
||||
test.run5();
|
||||
test.run6();
|
||||
test.run7();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run1() {
|
||||
Invoker<String, String> invoker = Invoker.create(String.class, "toLowerCase");
|
||||
@@ -34,4 +46,53 @@ public class InvokerTest {
|
||||
System.out.println(str);
|
||||
Assertions.assertEquals(str, invoker.invoke(null, str).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run4() {
|
||||
Invoker<Action, Void> invoker = Invoker.create(Action.class, "test1");
|
||||
Action action = new Action();
|
||||
invoker.invoke(action);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run5() {
|
||||
Invoker<Action, Void> invoker = Invoker.create(Action.class, "test2", String.class);
|
||||
Action action = new Action();
|
||||
invoker.invoke(action, "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run6() {
|
||||
Invoker<Action, Integer> invoker = Invoker.create(Action.class, "test3", String.class, int.class);
|
||||
Action action = new Action();
|
||||
int rs = invoker.invoke(action, "name", 1);
|
||||
System.out.println(rs);
|
||||
Assertions.assertEquals(3, rs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run7() {
|
||||
Invoker<Action, Integer> invoker = Invoker.create(Action.class, "test4", String.class, int.class);
|
||||
Action action = new Action();
|
||||
int rs = invoker.invoke(action, "name", 1);
|
||||
System.out.println(rs);
|
||||
Assertions.assertEquals(4, rs);
|
||||
}
|
||||
|
||||
public static class Action {
|
||||
|
||||
public void test1() {
|
||||
}
|
||||
|
||||
public void test2(String name) throws IOException {
|
||||
}
|
||||
|
||||
public int test3(String name, int id) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int test4(String name, int id) throws IOException {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user