use of org.structr.messaging.engine.entities.MessageSubscriber in project structr by structr.
the class MQTTClient method getTopics.
static String[] getTopics(MQTTClient thisClient) {
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
List<MessageSubscriber> subs = thisClient.getSubscribers();
String[] topics = new String[subs.size()];
for (int i = 0; i < subs.size(); i++) {
topics[i] = subs.get(i).getTopic();
}
return topics;
} catch (FrameworkException ex) {
logger.error("Couldn't retrieve client topics for MQTT subscription.");
return null;
}
}
use of org.structr.messaging.engine.entities.MessageSubscriber in project structr by structr.
the class KafkaClient method refreshSubscriptions.
static void refreshSubscriptions(KafkaClient thisClient) {
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
thisClient.getSubscribers().forEach((MessageSubscriber sub) -> {
try {
String topic = sub.getProperty(StructrApp.key(MessageSubscriber.class, "topic"));
if (topic != null) {
subscribeTopic(thisClient, topic);
}
} catch (FrameworkException e) {
logger.warn("Could not subscribe to topic in KafkaClient: " + e.getMessage());
}
});
tx.success();
} catch (FrameworkException ex) {
logger.error("Could not refresh subscriptions in KafkaClient: " + ex.getMessage());
}
}
use of org.structr.messaging.engine.entities.MessageSubscriber in project structr by structr.
the class SimpleMessagingTest method test01.
@Test
public void test01() {
try (final Tx tx = app.tx()) {
MessageClient client1 = app.create(MessageClient.class, "client1");
MessageSubscriber sub = app.create(MessageSubscriber.class, "sub");
List<MessageSubscriber> subList = new ArrayList<>();
subList.add(sub);
client1.setProperty(StructrApp.key(MessageClient.class, "subscribers"), subList);
sub.setProperty(StructrApp.key(MessageSubscriber.class, "topic"), "test");
sub.setProperty(StructrApp.key(MessageSubscriber.class, "callback"), "set(this, 'name', retrieve('message'))");
Scripting.replaceVariables(new ActionContext(securityContext, null), client1, "${{Structr.log('Sending message'); Structr.get('this').sendMessage('test','testmessage');}}");
assertEquals("testmessage", sub.getName());
tx.success();
} catch (FrameworkException ex) {
fail("Exception during test: " + ex.getMessage());
}
}
Aggregations