This commit is contained in:
kento2 2026-07-07 08:31:54 +02:00
parent 94061dbb8e
commit 60a0bc5093

View file

@ -22,10 +22,20 @@ public class MessageBroker {
this.dispatcher = nats.createDispatcher();
}
/**
* Runs blocking.
* publishes to the message broker
* @param subject <a href="https://docs.nats.io/nats-concepts/subjects">subject</a> to publish to
*/
public void publish(String subject, Document document) {
nats.publish(subject, DocumentRepository.toBytes(document));
}
/**
* Runs blocking.
* publishes to the message broker
* @param subject <a href="https://docs.nats.io/nats-concepts/subjects">subject</a> to publish to
*/
public void publish(String subject, Result<Document, String> result) {
this.publish(subject, ResultRepository.toDocument(result));
}
@ -54,6 +64,11 @@ public class MessageBroker {
});
}
/**
* Runs blocking.
* Executes a RPC call: The document is published and this method starts listening for incoming
* replies. The returned Result holds either a document with the requested data, or an error as a string
*/
public Result<Document, String> request(String subject, Document document) {
var response = nats.request(subject, DocumentRepository.toBytes(document)).join();
return ResultRepository.fromDocument(DocumentRepository.fromMessage(response));