All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.noear.solon.cloud.eventplus.CloudEventEntity Maven / Gradle / Ivy

There is a newer version: 3.0.5-M3
Show newest version
package org.noear.solon.cloud.eventplus;

import org.noear.snack.ONode;
import org.noear.solon.Solon;
import org.noear.solon.Utils;
import org.noear.solon.cloud.CloudClient;
import org.noear.solon.cloud.annotation.CloudEvent;
import org.noear.solon.cloud.exception.CloudEventException;
import org.noear.solon.cloud.model.Event;

/**
 * 云端事件实体
 *
 * 

 * //申明事件实体
 * @CloudEvent("user.create.event")
 * public class UserCreatedEvent implements CloudEventEntity{
 *     public long userId;
 * }
 *
 * UserCreatedEvent event = new UserCreatedEvent();
 * event.userId = 1;
 *
 * //发布事件
 * CloudClient.event().publish(event);
 *
 * //订阅事件
 * public class UserCreatedEventHandler implements CloudEventEntityHandler{
 *     public boolean handle(UserCreatedEvent event) throws Throwable{
 *         //
 *         return true;
 *     }
 * }
 *
 * 
* * @author 颖 * @since 1.5 */ public interface CloudEventEntity { /** * 发布事件 */ default boolean publish() throws CloudEventException { CloudEvent anno2 = this.getClass().getAnnotation(CloudEvent.class); if (anno2 == null) { throw new IllegalArgumentException("The entity is missing (@CloudEvent) annotations: " + this.getClass().getName()); } //支持${xxx}配置 String topic2 = Solon.cfg().getByTmpl(Utils.annoAlias(anno2.value(), anno2.topic())); //支持${xxx}配置 String group2 = Solon.cfg().getByTmpl(anno2.group()); String content = ONode.stringify(this); return CloudClient.event().publish(new Event(topic2, content).qos(anno2.qos()).group(group2).tags(anno2.tag()).channel(anno2.channel())); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy