diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Channel.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Channel.java new file mode 100644 index 00000000..469158f3 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Channel.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.base; + +/** + * @author: aoshiguchen + * @date: 2022/9/29 + */ +public interface Channel { + + /** + * 注册接收者 + * @param receiver 接收者 + */ + void registerReceiver(R receiver); + + /** + * 注销接收者 + * @param receiver 接收者 + */ + void unRegisterReceiver(R receiver); + + /** + * 设置调度器 + * @param dispatcher 调度器 + */ + void setDispatcher(Dis dispatcher); + + /** + * 发布消息 + * @param msg 消息 + */ + void publish(D msg); +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Publisher.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Publisher.java new file mode 100644 index 00000000..d33d5dba --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Publisher.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.base; + +/** + * @author: aoshiguchen + * @date: 2022/9/29 + */ +public interface Publisher { + /** + * 发布消息 + * @param msg 消息 + */ + void publish(D msg); + + /** + * 注册渠道 + * @param channel 渠道 + */ + void registerChannel(Ch channel); + + /** + * 注销渠道 + * @param channel 渠道 + */ + void unRegisterChannel(Ch channel); +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventMarket.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Receiver.java similarity index 87% rename from neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventMarket.java rename to neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Receiver.java index d8bb134f..ff12f524 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventMarket.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/Receiver.java @@ -19,12 +19,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package fun.asgc.neutrino.core.base.event; +package fun.asgc.neutrino.core.base; /** * @author: aoshiguchen - * @date: 2022/9/28 + * @date: 2022/9/29 */ -public interface EventMarket { +public interface Receiver { + /** + * 接收消息 + * @param msg + */ + void receive(D msg); } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEvent.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEvent.java index 66f9c7c4..44a773de 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEvent.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEvent.java @@ -21,48 +21,30 @@ */ package fun.asgc.neutrino.core.base.event; -import java.util.Map; -import java.util.Set; - /** * @author: aoshiguchen * @date: 2022/9/28 */ -public class ApplicationEvent implements Event { +public class ApplicationEvent implements Event { - @Override - public ApplicationEventSource source() { - return null; + private D data; + private ApplicationEventContext context; + + public ApplicationEvent() { + this.context = new ApplicationEventContext(); } @Override public D data() { - return null; + return this.data; } @Override public ApplicationEventContext context() { - return null; + return this.context; } - @Override - public String topic() { - return null; + public void setData(D data) { + this.data = data; } - - @Override - public Set tags() { - return null; - } - - @Override - public Map attachData() { - return null; - } - - @Override - public String id() { - return null; - } - } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventChannel.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventChannel.java new file mode 100644 index 00000000..2cb2170e --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventChannel.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.base.event; + +import fun.asgc.neutrino.core.base.CustomThreadFactory; +import fun.asgc.neutrino.core.base.Dispatcher; +import fun.asgc.neutrino.core.util.Assert; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author: aoshiguchen + * @date: 2022/9/29 + */ +public class ApplicationEventChannel implements EventChannel,ApplicationEventReceiver,Dispatcher>> { + private List> receiverList; + private Dispatcher> dispatcher; + private ThreadPoolExecutor threadPoolExecutor; + + public ApplicationEventChannel() { + this.receiverList = new ArrayList<>(); + this.threadPoolExecutor = new ThreadPoolExecutor(5, 20, 10L, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(), new CustomThreadFactory("ApplicationEventChannel")); + } + + @Override + public void registerReceiver(ApplicationEventReceiver receiver) { + Assert.notNull(receiver, "receiver不能为空!"); + if (this.receiverList.contains(receiver)) { + return; + } + this.receiverList.add(receiver); + } + + @Override + public void unRegisterReceiver(ApplicationEventReceiver receiver) { + Assert.notNull(receiver, "receiver不能为空!"); + if (!this.receiverList.contains(receiver)) { + return; + } + this.receiverList.remove(receiver); + } + + @Override + public void setDispatcher(Dispatcher> dispatcher) { + Assert.notNull(dispatcher, "dispatcher不能为空!"); + this.dispatcher = dispatcher; + } + + @Override + public void publish(ApplicationEvent msg) { + this.receiverList.forEach(receiver -> { + threadPoolExecutor.submit(() -> receiver.receive(msg)); + }); + } +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventContext.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventContext.java index ee7df041..ff2bb511 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventContext.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventContext.java @@ -21,9 +21,71 @@ */ package fun.asgc.neutrino.core.base.event; +import fun.asgc.neutrino.core.util.StringUtil; + +import java.util.*; + /** * @author: aoshiguchen * @date: 2022/9/28 */ public class ApplicationEventContext implements EventContext { + + private String id; + private String topic; + private Set tags; + private Object source; + private Date happenTime; + private Map attachData = new HashMap<>(); + + public ApplicationEventContext() { + this.id = StringUtil.genUUID(); + this.happenTime = new Date(); + } + + @Override + public Map attachData() { + return attachData; + } + + @Override + public String id() { + return id; + } + + @Override + public Date happenTime() { + return happenTime; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public S source() { + return (S)source; + } + + @Override + public String topic() { + return topic; + } + + @Override + public Set tags() { + return tags; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public void setTags(Set tags) { + this.tags = tags; + } + + public void setSource(S source) { + this.source = source; + } } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventPublisher.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventPublisher.java new file mode 100644 index 00000000..0f89147a --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventPublisher.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.base.event; + + +import fun.asgc.neutrino.core.util.Assert; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author: aoshiguchen + * @date: 2022/9/29 + */ +public class ApplicationEventPublisher implements EventPublisher,ApplicationEventChannel> { + private List> channelList; + + public ApplicationEventPublisher() { + this.channelList = new ArrayList<>(); + } + + @Override + public void publish(ApplicationEvent msg) { + this.channelList.forEach(channel -> channel.publish(msg)); + } + + @Override + public void registerChannel(ApplicationEventChannel channel) { + Assert.notNull(channel, "channel不能为空!"); + if (!this.channelList.contains(channel)) { + this.channelList.add(channel); + } + } + + @Override + public void unRegisterChannel(ApplicationEventChannel channel) { + Assert.notNull(channel, "channel不能为空!"); + this.channelList.remove(channel); + } +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventReceiver.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventReceiver.java new file mode 100644 index 00000000..d80fb4df --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventReceiver.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.base.event; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; + +/** + * @author: aoshiguchen + * @date: 2022/9/29 + */ +@Slf4j +public class ApplicationEventReceiver implements EventReceiver> { + + @Override + public void receive(ApplicationEvent msg) { + log.debug("ApplicationEventReceiver receive {}", JSONObject.toJSONString(msg)); + } + +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/Event.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/Event.java index 103eb6ae..75209edb 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/Event.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/Event.java @@ -21,20 +21,11 @@ */ package fun.asgc.neutrino.core.base.event; -import java.util.Map; -import java.util.Set; - /** * @author: aoshiguchen * @date: 2022/9/28 */ -public interface Event { - /** - * 获取事件源 - * @return 事件源 - */ - S source(); - +public interface Event { /** * 获取数据 * @return 数据 @@ -46,30 +37,4 @@ public interface Event tags(); - - /** - * 附加数据 - * @return 附加数据 - */ - Map attachData(); - - /** - * 事件ID - * @return 事件ID - */ - String id(); } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventSource.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventChannel.java similarity index 81% rename from neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventSource.java rename to neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventChannel.java index 678d9d2c..755366ae 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventSource.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventChannel.java @@ -21,10 +21,13 @@ */ package fun.asgc.neutrino.core.base.event; +import fun.asgc.neutrino.core.base.Channel; +import fun.asgc.neutrino.core.base.Dispatcher; + /** * @author: aoshiguchen - * @date: 2022/9/28 + * @date: 2022/9/29 */ -public interface EventSource { +public interface EventChannel, R extends EventReceiver, Dis extends Dispatcher> extends Channel { } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventContext.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventContext.java index 8d99b577..195341e8 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventContext.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventContext.java @@ -21,10 +21,48 @@ */ package fun.asgc.neutrino.core.base.event; +import java.util.Date; +import java.util.Map; +import java.util.Set; + /** * @author: wen.y * @date: 2022/9/28 */ public interface EventContext { + /** + * 获取事件源 + * @return 事件源 + */ + T source(); + /** + * 事件主题 + * 用于订阅一级过滤 + * @return 主题 + */ + String topic(); + /** + * 事件标签 + * 用于订阅二级过滤 + * @return 标签 + */ + Set tags(); + /** + * 附加数据 + * @return 附加数据 + */ + Map attachData(); + + /** + * 事件ID + * @return 事件ID + */ + String id(); + + /** + * 事件发生的时间 + * @return 事件发生的时间 + */ + Date happenTime(); } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventPublisher.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventPublisher.java index 4d212302..595f16a6 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventPublisher.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventPublisher.java @@ -21,10 +21,12 @@ */ package fun.asgc.neutrino.core.base.event; +import fun.asgc.neutrino.core.base.Publisher; + /** * @author: aoshiguchen * @date: 2022/9/28 */ -public interface EventPublisher { +public interface EventPublisher,Ch extends EventChannel> extends Publisher { } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventSource.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventReceiver.java similarity index 87% rename from neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventSource.java rename to neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventReceiver.java index a660e80b..1db4b7d4 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/ApplicationEventSource.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/base/event/EventReceiver.java @@ -21,10 +21,13 @@ */ package fun.asgc.neutrino.core.base.event; + +import fun.asgc.neutrino.core.base.Receiver; + /** * @author: aoshiguchen - * @date: 2022/9/28 + * @date: 2022/9/29 */ -public class ApplicationEventSource implements EventSource { +public interface EventReceiver> extends Receiver { } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/util/StringUtil.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/util/StringUtil.java index 16da2728..d2dd409b 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/util/StringUtil.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/util/StringUtil.java @@ -1107,4 +1107,11 @@ public class StringUtil { return arrayToDelimitedString(arr, ","); } + /** + * 生成UUID + * @return + */ + public static String genUUID() { + return UUID.randomUUID().toString().replace("-", "").toUpperCase(); + } } diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/base/event/Test1.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/base/event/Test1.java new file mode 100644 index 00000000..621e2fc0 --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/base/event/Test1.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.base.event; + +import com.google.common.collect.Sets; +import lombok.Data; +import lombok.experimental.Accessors; +import org.junit.Test; + +/** + * 应用事件测试 + * 1、异步执行 + * 2、业务解耦 + * 3、topic订阅 + * 4、支持多种模式无缝切换(本地模式、redis模式、rocketMQ模式、MQTT模式等) + * 5、不支持事务消息 + * @author: aoshiguchen + * @date: 2022/10/3 + */ +public class Test1 { + private ApplicationEventChannel channel = new ApplicationEventChannel<>(); + private ApplicationEventPublisher publisher = new ApplicationEventPublisher<>(); + + { + publisher.registerChannel(channel); + } + + @Test + public void test1() { + ApplicationEventReceiver receiver = new ApplicationEventReceiver() { + @Override + public void receive(ApplicationEvent msg) { + System.out.println("msg:" + msg); + } + }; + channel.registerReceiver(receiver); + + ApplicationEvent event = new ApplicationEvent<>(); + event.context().setId("123"); + event.context().setTopic("student"); + event.context().setTags(Sets.newHashSet("create")); + event.setData(new Student().setId("1").setName("张三").setAge(28).setSex("男")); + publisher.publish(event); + } + + @Accessors(chain = true) + @Data + public static class Student { + private String id; + private String name; + private Integer age; + private String sex; + } +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/util/ClassUtilTest.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/util/ClassUtilTest.java index ce0a5b92..bc088ff9 100644 --- a/neutrino-core/src/test/java/fun/asgc/neutrino/core/util/ClassUtilTest.java +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/util/ClassUtilTest.java @@ -80,5 +80,4 @@ public class ClassUtilTest { Set> c = ClassUtil.scan("fun.asgc.neutrino.proxy.server", url); System.out.println(c); } - }