/** * Emits given incremental update to subscription queries matching given filter. If an {@code update} is {@code * null}, emit will be skipped. In order to send nullable updates, use {@link #emit(Class, Predicate, * SubscriptionQueryUpdateMessage)} or {@link #emit(Predicate, SubscriptionQueryUpdateMessage)} methods. * * @param filter predicate on subscription query message used to filter subscription queries * @param update incremental update * @param <U> the type of the update */ default <U> void emit(Predicate<SubscriptionQueryMessage<?, ?, U>> filter, U update) { if (update != null) { emit(filter, GenericSubscriptionQueryUpdateMessage.asUpdateMessage(update)); } }
/** * Initializes a {@link DefaultQueryGateway} as specified through this Builder. * * @return a {@link DefaultQueryGateway} as specified through this Builder */ public DefaultQueryGateway build() { return new DefaultQueryGateway(this); }
/** * Instantiate a Builder to be able to create a {@link DefaultQueryGateway}. * <p> * The {@code dispatchInterceptors} is defaulted to an empty list. The {@link QueryBus} is a * <b>hard requirement</b> and as such should be provided. * * @return a Builder to be able to create a {@link DefaultQueryGateway} */ public static Builder builder() { return new Builder(); }
private QueryBus buildQueryBus(Configuration c) { SimpleQueryBus localSegment = SimpleQueryBus.builder() .transactionManager(c.getComponent(TransactionManager.class, NoTransactionManager::instance)) .errorHandler(c.getComponent(QueryInvocationErrorHandler.class, () -> LoggingQueryInvocationErrorHandler.builder().build())) .queryUpdateEmitter(c.queryUpdateEmitter()) .messageMonitor(c.messageMonitor(QueryBus.class, "localQueryBus")) .build(); AxonServerQueryBus queryBus = new AxonServerQueryBus(c.getComponent(AxonServerConnectionManager.class), c.getComponent(AxonServerConfiguration.class), c.queryUpdateEmitter(), localSegment, c.messageSerializer(), c.serializer(), c.getComponent(QueryPriorityCalculator.class, () -> new QueryPriorityCalculator() {})); c.onShutdown(queryBus::disconnect); return queryBus; }
/** * Returns a {@link DefaultQueryGateway} that will use the configuration's {@link QueryBus} to dispatch queries. * * @param config The configuration that supplies the query bus. * @return The default query gateway. */ protected QueryGateway defaultQueryGateway(Configuration config) { return DefaultQueryGateway.builder().queryBus(config.queryBus()).build(); }
@Override public <R, Q> Stream<R> scatterGather(String queryName, Q query, ResponseType<R> responseType, long timeout, TimeUnit timeUnit) { GenericQueryMessage<Q, R> queryMessage = new GenericQueryMessage<>(query, queryName, responseType); return queryBus.scatterGather(processInterceptors(queryMessage), timeout, timeUnit) .map(QueryResponseMessage::getPayload); }
@Override public Flux<U> updates() { return delegate.updates(); }
@Override public Mono<I> initialResult() { return delegate.initialResult(); }
@Override public boolean cancel() { return delegate.cancel(); } }
@Override public <U> void emit(Predicate<SubscriptionQueryMessage<?, ?, U>> filter, SubscriptionQueryUpdateMessage<U> update) { runOnAfterCommitOrNow(() -> doEmit(filter, intercept(update))); }
/** * Creates default backpressure, using Project Reactor's FluxSink.OverflowStrategy ERROR strategy. * * @return initialized backpressure, using Project Reactor's FluxSink.OverflowStrategy ERROR strategy */ public static SubscriptionQueryBackpressure defaultBackpressure() { return new SubscriptionQueryBackpressure(FluxSink.OverflowStrategy.ERROR); }
/** * Creates a Query Response Message with given {@code declaredType} and {@code exception}. * * @param declaredType The declared type of the Query Response Message to be created * @param exception The Exception describing the cause of an error * @param <R> The type of the payload * @return a message containing exception result */ public static <R> QueryResponseMessage<R> asResponseMessage(Class<R> declaredType, Throwable exception) { return new GenericQueryResponseMessage<>(declaredType, exception); }
/** * Initializes a {@link SimpleQueryBus} as specified through this Builder. * * @return a {@link SimpleQueryBus} as specified through this Builder */ public SimpleQueryBus build() { return new SimpleQueryBus(this); }
/** * Initializes a {@link LoggingQueryInvocationErrorHandler} as specified through this Builder. * * @return a {@link LoggingQueryInvocationErrorHandler} as specified through this Builder */ public LoggingQueryInvocationErrorHandler build() { return new LoggingQueryInvocationErrorHandler(this); }
@Override public void complete(Predicate<SubscriptionQueryMessage<?, ?, ?>> filter) { runOnAfterCommitOrNow(() -> doComplete(filter)); }
/** * Instantiate a Builder to be able to create a {@link SimpleQueryUpdateEmitter}. * <p> * The {@link MessageMonitor} is defaulted to a {@link NoOpMessageMonitor}. * * @return a Builder to be able to create a {@link SimpleQueryUpdateEmitter} */ public static Builder builder() { return new Builder(); }
/** * Instantiate a {@link LoggingQueryInvocationErrorHandler} based on the fields contained in the {@link Builder}. * * @param builder the {@link Builder} used to instantiate a {@link LoggingQueryInvocationErrorHandler} instance */ protected LoggingQueryInvocationErrorHandler(Builder builder) { builder.validate(); this.logger = builder.logger; }
/** * Initializes a {@link SimpleQueryUpdateEmitter} as specified through this Builder. * * @return a {@link SimpleQueryUpdateEmitter} as specified through this Builder */ public SimpleQueryUpdateEmitter build() { return new SimpleQueryUpdateEmitter(this); }
/** * Instantiate a {@link SimpleQueryUpdateEmitter} based on the fields contained in the {@link Builder}. * * @param builder the {@link Builder} used to instantiate a {@link SimpleQueryUpdateEmitter} instance */ protected SimpleQueryUpdateEmitter(Builder builder) { builder.validate(); this.updateMessageMonitor = builder.updateMessageMonitor; }