CommandRequest

public final class CommandRequest extends ClientRequest

Allows to post a command optionally subscribing to events that are immediate results of handling this command.

Usage example:


Subscription loginSubscription =
    client.asGuest()
          .command(logInUser)
          .observe(UserLoggedIn.class, (event, context) -> { ... })
          .observe(UserAlreadyLoggedIn.class, (rejection, context) -> { ... })
          .onStreamingError((throwable) -> { ... })
          .post();

The subscription obtained from the post should be cancelled to preserve both client-side and server-side resources. The moment of cancelling the subscriptions depends on the nature of the posted command and the outcome expected by the client application.

Functions

Link copied to clipboard
public CommandRequest observe<E extends EventMessage>(Class<E> type, EventConsumer<E> consumer)
Adds the passed event consumer to the subscribers of the event of the passed type.
public CommandRequest observe<E extends EventMessage>(Class<E> type, Consumer<E> consumer)
Adds the passed consumer to the subscribers of the event of the passed type.
Link copied to clipboard
public CommandRequest onConsumingError(ConsumerErrorHandler<EventMessage> handler)
Assigns a handler for errors occurred in consumers of events.
Link copied to clipboard
Assigns a handler for an error occurred on the server-side (such as validation error) in response to posting a command.
Link copied to clipboard
Assigns a handler for errors occurred when delivering events.
Link copied to clipboard
public ImmutableSet<Subscription> post()
Subscribes the consumers to events to receive events resulting from the command as they happen, then sends the command to the server.
Link copied to clipboard
public void postAndForget()
Posts the command without subscribing to events that may be generated during the command handling.

Inherited functions

Link copied to clipboard
protected final Client client()
Obtains the client instance that will perform the request.
Link copied to clipboard
public CommandRequest command(CommandMessage c)
Creates a builder for customizing command request.
Link copied to clipboard
public QueryRequest<S> select<S extends EntityState>(Class<S> type)
Creates a builder for constructing a query for messages of the specified type.
Link copied to clipboard
public SubscriptionRequest<S> subscribeTo<S extends EntityState>(Class<S> type)
Creates a builder for customizing subscription for the passed entity state type.
Link copied to clipboard
public EventSubscriptionRequest<E> subscribeToEvent<E extends EventMessage>(Class<E> type)
Creates a builder for customizing subscription for the passed event type.
Link copied to clipboard
protected final UserId user()
Obtains the ID of the user of the request.