Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle publisher returned from non-producer method #57

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public <B> void invoke(MethodJob<B, ?> job, B bean, JobRunContext context) {

if (method.getArguments().length == 0) {
context.message(null);
handleResult(configuration, context, executor(context, configuration).apply(() -> {
handleResult(producer, configuration, context, executor(context, configuration).apply(() -> {
if (configuration.getFork() > 1) {
ParallelFlux<Object> resultsOfParallelExecution = Flux.range(0, configuration.getFork())
.parallel(configuration.getFork())
Expand Down Expand Up @@ -115,7 +115,7 @@ public <B> void invoke(MethodJob<B, ?> job, B bean, JobRunContext context) {
return method.invoke(bean);
}));
} else if (method.getArguments().length == 1) {
handleResult(configuration, context, executor(context, configuration).apply(() -> {
handleResult(producer, configuration, context, executor(context, configuration).apply(() -> {
JobConfiguration.ConsumerQueueConfiguration queueConfiguration = configuration.getConsumer();
Flux<? extends QueueMessage<?>> messages = Flux.from(
queues(queueConfiguration.getQueueType()).readMessages(
Expand Down Expand Up @@ -185,14 +185,25 @@ private <T> Function<Callable<T>, Publisher<T>> executor(JobRunContext context,
return s -> distributedJobExecutor.execute(context, s);
}

protected void handleResult(JobConfiguration configuration, JobRunContext callback, Publisher<Object> resultPublisher) {
protected void handleResult(boolean producer, JobConfiguration configuration, JobRunContext callback, Publisher<Object> resultPublisher) {
Object result = Flux.from(resultPublisher).blockFirst();

if (result == null) {
callback.finished();
return;
}

if (!producer && result instanceof Publisher<?> p) {
Mono.from(p)
.doOnNext(callback::result)
.doOnError(callback::error)
.doFinally(signalType -> callback.finished())
.block();

return;
}


String queueName = configuration.getProducer().getQueueName();

JobQueues sender = queues(configuration.getProducer().getQueueType());
Expand Down
Loading