import org.osgi.service.component.annotations.*; import org.osgi.enroute.easse.event.Topic; @Component(name = "example-publisher") public class EventPublisher { @Reference(target = "(" + EasseConstants.ID + "=example-topic)") private Topic topic; public void publishEvent(String message) { topic.publish(message); } } import org.osgi.service.component.annotations.*; import org.osgi.enroute.easse.event.EventHandler; import org.osgi.enroute.easse.event.Topic; import org.osgi.enroute.easse.event.Type; @Component(name = "example-subscriber") public class EventSubscriber { @Reference(target = "(" + EasseConstants.ID + "=example-topic)") private Topic topic; @EventHandler(type = Type.FILTERED) public void handleEvent(String message) { System.out.println("Received event: " + message); } @Activate protected void activate() { topic.subscribe(this::handleEvent); } @Deactivate protected void deactivate() { topic.unsubscribe(this::handleEvent); } } easse.simple.connection.url = amqp://localhost easse.simple.connection.username = guest easse.simple.connection.password = guest


上一篇:
下一篇:
切换中文