类似git操作的eventbus
- 非常轻量,代码简单,大小只有8k
- git命令操作,api友好
- 支持编程式和注解
- 支持jdk8+
Maven
<dependency>
<groupId>io.github.kongweiguang</groupId>
<artifactId>van</artifactId>
<version>0.1</version>
</dependency>
Gradle
implementation 'io.github.kongweiguang:van:0.1'
Gradle-Kotlin
implementation("io.github.kongweiguang:van:0.1")
详情看test的例子
public class PushTopicTest {
String topic = "topic.test1";
@Test
void test() throws Exception {
//拉取消息
hub().pull(topic, m -> {
System.out.println(m.id());
System.out.println(m.content());
});
//推送消息
hub().push(topic, "content");
hub().push(topic, "content", e -> System.out.println("callback 1 -> " + e));
hub().push(Action.of(topic, "content"));
hub().push(Action.of(topic, "content"), e -> System.out.println("callback 2 -> " + e));
}
}
public class PushObjMethodTest {
@Test
void test1() throws Exception {
//设置拉取消息的处理
hub().pull(new MyHandler());
//推送tipic为bala的消息
hub().push(Action.of("bala", new User(1, "k", new String[]{"h"})), object -> System.out.println("object = " + object));
//推送topic为bala1的消息
hub().push("bala1", new User(1, "k", new String[]{"h"}), object -> System.out.println("object = " + object));
//推送user类的topic
hub().push(new User(1, "k", new String[]{"h"}), object -> System.out.println("object = " + object));
Van.<User, String>hub().push(new User(1, "k", new String[]{"h"}), object -> System.out.println("object = " + object));
}
}