public interface FluxCapacitor
To start handling messages build an instance of this API and invoke startTracking(java.lang.Object...).
Once you are handling messages you can simply use the static methods provided (e.g. to publish messages etc). In those cases it is not necessary to inject an instance of this API. This minimizes the need for dependencies in your functional classes and maximally cashes in on location transparency.
To build an instance of this client check out DefaultFluxCapacitor.
| Modifier and Type | Field and Description |
|---|---|
static AtomicReference<FluxCapacitor> |
applicationInstance
Flux Capacitor instance set by the current application.
|
static ThreadLocal<FluxCapacitor> |
instance
Flux Capacitor instance bound to the current thread.
|
| Modifier and Type | Method and Description |
|---|---|
Client |
client()
Returns the low level client used by this FluxCapacitor instance to interface with the Flux Capacitor service.
|
CommandGateway |
commandGateway()
Returns the gateway for command messages.
|
ErrorGateway |
errorGateway()
Returns the gateway for any error messages published while handling a command or query.
|
EventGateway |
eventGateway()
Returns the message gateway for application events.
|
EventSourcing |
eventSourcing()
Returns a client to assist with event sourcing.
|
static FluxCapacitor |
get()
Returns the FluxCapacitor client bound to the current thread or else set by the current application.
|
static String |
getProperty(String key)
Returns the property value registered with the given key.
|
static String |
getProperty(String key,
String defaultValue)
Returns the property value registered with the given key.
|
KeyValueStore |
keyValueStore()
Returns a client for the key value service offered by Flux Capacitor.
|
static <T> Model<T> |
loadAggregate(String id,
Class<T> modelType)
Loads the most recent aggregate root of type
T with given id. |
MetricsGateway |
metricsGateway()
Returns the gateway for metrics events.
|
Properties |
properties()
Returns custom properties registered with this FluxCapacitor instance.
|
static void |
publishEvent(Object event)
Publishes the given application event.
|
static void |
publishEvent(Object payload,
Metadata metadata)
Publishes an event with given payload and metadata.
|
static void |
publishMetrics(Object metrics)
Publishes a metrics event.
|
static void |
publishMetrics(Object payload,
Metadata metadata)
Publishes a metrics event with given payload and metadata.
|
static <R> CompletableFuture<R> |
query(Object query)
Sends the given query and returns a future that will be completed with the query's result.
|
static <R> CompletableFuture<R> |
query(Object payload,
Metadata metadata)
Sends a query with given payload and metadata and returns a future that will be completed with the query's
result.
|
static <R> R |
queryAndWait(Object query)
Sends the given query and returns the query's result.
|
static <R> R |
queryAndWait(Object payload,
Metadata metadata)
Sends a query with given payload and metadata and returns the query's result.
|
QueryGateway |
queryGateway()
Returns the gateway for query messages.
|
default Registration |
registerLocalHandlers(List<?> handlers)
Registers given message handlers for immediate handling of messages as they are published by the application.
|
default Registration |
registerLocalHandlers(Object... handlers)
Registers given message handlers for immediate handling of messages as they are published by the application.
|
ResultGateway |
resultGateway()
Returns the gateway for result messages sent by handlers of commands and queries.
|
Scheduler |
scheduler()
Returns the message scheduling client.
|
static void |
sendAndForgetCommand(Object command)
Sends the given command and don't wait for a result.
|
static void |
sendAndForgetCommand(Object payload,
Metadata metadata)
Sends a command with given payload and metadata and don't wait for a result.
|
static <R> CompletableFuture<R> |
sendCommand(Object command)
Sends the given command and returns a future that will be completed with the command's result.
|
static <R> CompletableFuture<R> |
sendCommand(Object payload,
Metadata metadata)
Sends a command with given payload and metadata and returns a future that will be completed with the command's
result.
|
static <R> R |
sendCommandAndWait(Object command)
Sends the given command and returns the command's result.
|
static <R> R |
sendCommandAndWait(Object payload,
Metadata metadata)
Sends a command with given payload and metadata and returns a future that will be completed with the command's
result.
|
default Registration |
startTracking(List<?> handlers)
Registers given handlers and initiates message tracking.
|
default Registration |
startTracking(Object... handlers)
Registers given handlers and initiates message tracking (i.e.
|
Tracking |
tracking(MessageType messageType)
Returns a client to assist with the tracking of a given message type.
|
static final AtomicReference<FluxCapacitor> applicationInstance
static final ThreadLocal<FluxCapacitor> instance
static FluxCapacitor get()
static void publishEvent(Object event)
Message in which case it will be
published as is. Otherwise the event is published using the passed value as payload without additional metadata.
Note that the published event will not be available for event sourcing as it is does not belong to any aggregate.
static void publishEvent(Object payload, Metadata metadata)
for more infostatic void sendAndForgetCommand(Object command)
Message in which
case it will be sent as is. Otherwise the command is published using the passed value as payload without
additional metadata.to send a command and inspect its resultstatic void sendAndForgetCommand(Object payload, Metadata metadata)
to send a command and inspect its resultstatic <R> CompletableFuture<R> sendCommand(Object command)
Message in which case it will be sent as is. Otherwise the command is published using
the passed value as payload without additional metadata.static <R> CompletableFuture<R> sendCommand(Object payload, Metadata metadata)
static <R> R sendCommandAndWait(Object command)
Message in which case it will be sent as is. Otherwise the command is published
using the passed value as payload without additional metadata.static <R> R sendCommandAndWait(Object payload, Metadata metadata)
static <R> CompletableFuture<R> query(Object query)
Message in which case it will be sent as is. Otherwise the query is published using the
passed value as payload without additional metadata.static <R> CompletableFuture<R> query(Object payload, Metadata metadata)
static <R> R queryAndWait(Object query)
Message in which case it will be sent as is. Otherwise the query is published using the
passed value as payload without additional metadata.static <R> R queryAndWait(Object payload, Metadata metadata)
static void publishMetrics(Object metrics)
Message in which case it will be sent as
is. Otherwise the metrics event is published using the passed value as payload without additional metadata.
Metrics events can be published in any form to log custom performance metrics about an application.
static void publishMetrics(Object payload, Metadata metadata)
static <T> Model<T> loadAggregate(String id, Class<T> modelType)
T with given id.static String getProperty(String key)
System.getProperty(String)static String getProperty(String key, String defaultValue)
System.getProperty(String). If the property is also not
known as system property the given default value will be returned.default Registration startTracking(Object... handlers)
HandleCommand). Depending on this
inspection message tracking will commence for any handled message types. To stop tracking at any time invoke
Registration.cancel() on the returned object.
Note that an exception may be thrown if tracking for a given message type is already in progress.
Note also that it will generally not be necessary to ever invoke this method manually if you have you use Spring to configure your application.
default Registration startTracking(List<?> handlers)
for more infodefault Registration registerLocalHandlers(Object... handlers)
HandleCommand).
If a published message can be handled locally it will not be published to the Flux Capacitor service. Local handling of messages may come in handy in several situations: e.g. when the message is expressly meant to be handled only by the current application or if the message needs to be handled as quickly as possible. However, in most cases it will not be necessary to register any local handlers.
To stop listening for locally published messages invoke Registration.cancel() on the returned object.
default Registration registerLocalHandlers(List<?> handlers)
for more infoEventSourcing eventSourcing()
Scheduler scheduler()
KeyValueStore keyValueStore()
CommandGateway commandGateway()
QueryGateway queryGateway()
EventGateway eventGateway()
eventSourcing() to publish events belonging to
an aggregate.ResultGateway resultGateway()
ErrorGateway errorGateway()
MetricsGateway metricsGateway()
Tracking tracking(MessageType messageType)
Client client()
Properties properties()
Copyright © 2019 Flux Capacitor. All rights reserved.