a
This commit is contained in:
parent
be248bfea9
commit
d9baa4113e
3 changed files with 15 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ import io.nats.client.Dispatcher;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
@ -73,4 +74,11 @@ public class MessageBroker {
|
||||||
var response = nats.request(subject, DocumentRepository.toBytes(document)).join();
|
var response = nats.request(subject, DocumentRepository.toBytes(document)).join();
|
||||||
return ResultRepository.fromDocument(DocumentRepository.fromMessage(response));
|
return ResultRepository.fromDocument(DocumentRepository.fromMessage(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <S> S unwrap(Result<S, String> result, String message) {
|
||||||
|
Optional<String> err = result.getFailure();
|
||||||
|
if (err.isPresent())
|
||||||
|
throw new RuntimeException(message + ": " + err.orElseThrow());
|
||||||
|
return result.getSuccess().orElseThrow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package de.kentoj.scrowlib.messaging;
|
||||||
|
|
||||||
|
public class RemoteException extends RuntimeException {
|
||||||
|
public RemoteException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,10 +8,4 @@ import java.util.Optional;
|
||||||
|
|
||||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||||
public class ResultUtils {
|
public class ResultUtils {
|
||||||
public static <S> S unwrap(Result<S, String> result, String message) {
|
|
||||||
Optional<String> err = result.getFailure();
|
|
||||||
if (err.isPresent())
|
|
||||||
throw new RuntimeException(message + ": " + err.orElseThrow());
|
|
||||||
return result.getSuccess().orElseThrow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue