use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.
the class AggregateCommandEndpointShould method setUp.
@Before
public void setUp() {
projectId = ProjectId.newBuilder().setId(Identifiers.newUuid()).build();
final CommandStore commandStore = mock(CommandStore.class);
final CommandBus.Builder commandBus = CommandBus.newBuilder().setMultitenant(true).setCommandStore(commandStore);
final BoundedContext boundedContext = newBoundedContext(commandBus);
subscriber = new Subscriber();
boundedContext.getEventBus().register(subscriber);
repository = new ProjectAggregateRepository(boundedContext);
repositorySpy = spy(repository);
}
use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.
the class CommandService method post.
@SuppressWarnings("MethodDoesntCallSuperMethod")
// as we override default implementation with `unimplemented` status.
@Override
public void post(Command request, StreamObserver<Response> responseObserver) {
final CommandClass commandClass = CommandClass.of(request);
final BoundedContext boundedContext = boundedContextMap.get(commandClass);
if (boundedContext == null) {
handleUnsupported(request, responseObserver);
} else {
final CommandBus commandBus = boundedContext.getCommandBus();
commandBus.post(request, responseObserver);
}
}
use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.
the class MultiTenantCommandBusShould method have_failure_bus_if_no_custom_set.
@Test
public void have_failure_bus_if_no_custom_set() {
final CommandBus bus = CommandBus.newBuilder().setCommandStore(commandStore).build();
assertNotNull(bus.failureBus());
}
use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.
the class MultiTenantCommandBusShould method allow_to_specify_failure_bus_via_builder.
@Test
public void allow_to_specify_failure_bus_via_builder() {
final FailureBus expectedFailureBus = mock(FailureBus.class);
final CommandBus commandBus = CommandBus.newBuilder().setCommandStore(commandStore).setFailureBus(expectedFailureBus).build();
assertNotNull(commandBus);
final FailureBus actualFailureBus = commandBus.failureBus();
assertEquals(expectedFailureBus, actualFailureBus);
}
use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.
the class ProcessManager method newRouterFor.
/**
* Creates a new {@link CommandRouter}.
*
* <p>A {@code CommandRouter} allows to create and post one or more commands
* in response to a command received by the {@code ProcessManager}.
*
* <p>A typical usage looks like this:
*
* <pre>
* {@literal @}Assign
* CommandRouted on(MyCommand message, CommandContext context) {
* // Create new command messages here.
* return newRouterFor(message, context)
* .add(messageOne)
* .add(messageTwo)
* .routeAll();
* }
* </pre>
*
* <p>The routed commands are created on behalf of the actor of the original command.
* That is, the {@code actor} and {@code zoneOffset} fields of created {@code CommandContext}
* instances will be the same as in the incoming command.
*
* @param commandMessage the source command message
* @param commandContext the context of the source command
* @return new {@code CommandRouter}
*/
protected CommandRouter newRouterFor(Message commandMessage, CommandContext commandContext) {
checkNotNull(commandMessage);
checkNotNull(commandContext);
final CommandBus commandBus = ensureCommandBus();
final CommandRouter router = new CommandRouter(commandBus, commandMessage, commandContext);
return router;
}
Aggregations