Sto usando reattore 2 e Spring 4. Ecco il codice tipico che ho - un Consumer
lavorare con un repositoryGestione delle eccezioni di Reactor Primavera
@Consumer
public class ApplicationService {
@Selector(value="/applications/id", type = SelectorType.URI)
@ReplyTo
public Application byApplicationId(String id) throws ApplicationNotFoundException {
Application app = appRepo.findOne(id);
if(app == null)
throw new ApplicationNotFoundException("Application `" + id + "` could not be found.");
return app;
}
}
Poi ho un controller che passa la richiesta a un eventBus
in cui mi passa le richieste e restituisce un Promise
@RestController
@RequestMapping("/applications")
public class ApplicationsController {
@RequestMapping(value = "/{id}", method = GET, produces = APPLICATION_JSON_VALUE)
public Promise<Event<Application>> byApplicationId(@PathVariable final String id) {
final Promise<Event<Application>> p = Promises.prepare(env);
eventBus.sendAndReceive("/applications/id", Event.wrap(id), p);
return p;
}
}
le cose funzionano, ma in caso di ApplicationService
un'eccezione Promise
s valore non è impostato, ma ottengo seguente in th e console:
16:46:58.003 [main] ERROR reactor.bus.EventBus - null
java.lang.reflect.UndeclaredThrowableException
at org.springframework.util.ReflectionUtils.rethrowRuntimeException(ReflectionUtils.java:302)
...
Caused by: com.metlife.harmony.exceptions.ApplicationNotFoundException: Application `2860c555-0bc4-45e6-95ea-f724ae3f4464` could not be found.
at com.metlife.harmony.services.ApplicationService.byApplicationId(ApplicationService.java:46) ~[classes/:?]
...
Caused by: reactor.core.support.Exceptions$ValueCause: Exception while signaling value: reactor.bus.Event.class : Event{id=null, headers={}, [email protected], key=/applications/id, data=2860c555-0bc4-45e6-95ea-f724ae3f4464}
domande sono:
posso utilizzare reattore e
eventBus
in modo sbagliato? e se sì, qual è il modo giustoforse questa funzionalità non è ancora implementato
'eventBus.sendAndReceive ("/ applicazioni/id", Event.wrap (id), p);' esso non cuase errore di casting? –
@AnadiMisra a che punto? – EvgeniySharapov
Stavo provando il tuo codice per curiosità e ho ottenuto questo 'Il metodo sendAndReceive (Oggetto, Evento , Consumer) nel tipo EventBus non è applicabile per gli argomenti (String, Evento >)' a quello line, my Promise object 'Promise > response = Promises.prepare (env);' –