doc
This commit is contained in:
parent
94061dbb8e
commit
60a0bc5093
1 changed files with 16 additions and 1 deletions
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue