1 - topic注解
topic 注解提供对 subscribe 的支持
@topic
注解用来订阅某个主题, pubsubName, name, metadata 分别对应 dapr pub/sub API 中的 pubsubName, topic,metadata 字段:
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Topic {
String name();
String pubsubName();
String metadata() default "{}";
// 用于匹配传入的 cloud event 的规则。
Rule rule() default @Rule(match = "", priority = 0);
}
以下是 @topic 注解使用的典型例子:
@Topic(name = "testingtopic", pubsubName = "${myAppProperty:messagebus}")
@PostMapping(path = "/testingtopic")
public Mono<Void> handleMessage(@RequestBody(required = false) CloudEvent<?> cloudEvent) {
......
}
2 - rule注解
rule 注解用来表述匹配规则
@topic
注解用来表述匹配规则。
@Documented
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Rule {
// 用于匹配传入的 cloud event 的通用表达式语言( Common Expression Language / CEL)表达。
String match();
// 规则的优先级,用于排序。最低的数字有更高的优先权。
int priority();
}
以下是 @rule 注解使用的典型例子:
@Topic(name = "testingtopic", pubsubName = "${myAppProperty:messagebus}",
rule = @Rule(match = "event.type == \"v2\"", priority = 1))
@PostMapping(path = "/testingtopicV2")
public Mono<Void> handleMessageV2(@RequestBody(required = false) CloudEvent cloudEvent) {
......
}