Search in sources :

Example 11 with CommandBus

use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.

the class ProcessManagerRepository method findOrCreate.

/**
 * Loads or creates a process manager by the passed ID.
 *
 * <p>The process manager is created if there was no manager with such an ID stored before.
 *
 * <p>The repository injects {@code CommandBus} from its {@code BoundedContext} into the
 * instance of the process manager so that it can post commands if needed.
 *
 * @param id the ID of the process manager to load
 * @return loaded or created process manager instance
 */
@Override
@CheckReturnValue
protected P findOrCreate(I id) {
    final P result = super.findOrCreate(id);
    final CommandBus commandBus = getBoundedContext().getCommandBus();
    result.setCommandBus(commandBus);
    return result;
}
Also used : CommandBus(io.spine.server.commandbus.CommandBus) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 12 with CommandBus

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<Ack> 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);
    }
}
Also used : CommandClass(io.spine.core.CommandClass) CommandBus(io.spine.server.commandbus.CommandBus)

Example 13 with CommandBus

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);
}
Also used : CommandBus(io.spine.server.commandbus.CommandBus) FailureBus(io.spine.server.failure.FailureBus) Test(org.junit.Test)

Example 14 with CommandBus

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);
    }
}
Also used : CommandClass(io.spine.type.CommandClass) CommandBus(io.spine.server.commandbus.CommandBus)

Example 15 with CommandBus

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());
}
Also used : CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Aggregations

CommandBus (io.spine.server.commandbus.CommandBus)18 Test (org.junit.Test)10 Ack (io.spine.core.Ack)7 Command (io.spine.core.Command)7 TenantId (io.spine.core.TenantId)6 ProjectId (io.spine.test.aggregate.ProjectId)4 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)3 IdempotencyGuardTestEnv.newProjectId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId)3 IdempotencyGuardTestEnv.newTenantId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId)3 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)3 IgTestAggregate (io.spine.server.aggregate.given.aggregate.IgTestAggregate)3 StringValue (com.google.protobuf.StringValue)2 CommandEnvelope (io.spine.core.CommandEnvelope)2 Event (io.spine.core.Event)2 BoundedContext (io.spine.server.BoundedContext)2 TestAggregate (io.spine.server.aggregate.given.aggregate.TestAggregate)2 Set (java.util.Set)2 Message (com.google.protobuf.Message)1 StreamObserver (io.grpc.stub.StreamObserver)1 Command (io.spine.base.Command)1