transfer money operation
This commit is contained in:
@@ -2,8 +2,11 @@ package com.mz.reactor.ddd.common.components.bus.impl;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.Message;
|
||||
import com.mz.reactor.ddd.common.components.bus.ApplicationMessageBus;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.DirectProcessor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxSink;
|
||||
import reactor.core.publisher.ReplayProcessor;
|
||||
@@ -14,17 +17,21 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class ApplicationMessageBusImpl implements ApplicationMessageBus {
|
||||
|
||||
private final ReplayProcessor<Message> messages = ReplayProcessor.create(1);
|
||||
private static final Log log = LogFactory.getLog(ApplicationMessageBusImpl.class);
|
||||
|
||||
private final DirectProcessor<Message> messages = DirectProcessor.create();
|
||||
|
||||
private final FluxSink<Message> messagesSink = messages.sink();
|
||||
|
||||
@Override
|
||||
public <M extends Message> void publishMessage(M message) {
|
||||
log.info(String.format("publishMessage -> messageBusId: %s, message: %s",this.hashCode(), message));
|
||||
Optional.ofNullable(message).ifPresent(messagesSink::next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Message> messagesStream() {
|
||||
log.info("messagesStream -> " + this.hashCode());
|
||||
return messages.publishOn(Schedulers.parallel());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,15 @@ import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
||||
|
||||
public enum HttpErrorHandler {
|
||||
FN;
|
||||
|
||||
public <E extends Throwable> Mono<ServerResponse> onError(E e, ServerRequest req) {
|
||||
public <E extends Throwable> Mono<ServerResponse> onError(E e, ServerRequest req, Consumer<E> logger) {
|
||||
logger.accept(e);
|
||||
return Mono.just(ErrorMessage.builder().error(e.getMessage()).build())
|
||||
.flatMap(error -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mz.reactor.ddd.common.components.http;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -8,9 +9,12 @@ import static org.springframework.web.reactive.function.BodyInserters.fromObject
|
||||
|
||||
public interface HttpHandler {
|
||||
|
||||
RouterFunction<ServerResponse> route();
|
||||
|
||||
default <T> Mono<ServerResponse> mapToResponse(T result) {
|
||||
return ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8).body(fromObject(result));
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||
.body(fromObject(result));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user