Skip to content

Add defaultEventSource to WorkflowApplication#1556

Open
matheusandre1 wants to merge 1 commit into
open-workflow-specification:mainfrom
matheusandre1:issue1554
Open

Add defaultEventSource to WorkflowApplication#1556
matheusandre1 wants to merge 1 commit into
open-workflow-specification:mainfrom
matheusandre1:issue1554

Conversation

@matheusandre1

Copy link
Copy Markdown
Contributor

Many thanks for submitting your Pull Request ❤️!

What this PR does / why we need it: Closes: #1554

Special notes for reviewers:

Additional information (if needed):

@matheusandre1
matheusandre1 marked this pull request as ready for review July 22, 2026 18:32
@matheusandre1
matheusandre1 requested a review from fjtirado as a code owner July 22, 2026 18:32
@ricardozanini

Copy link
Copy Markdown
Collaborator

@matheusandre1 you must sign your commits with -S.

@matheusandre1

Copy link
Copy Markdown
Contributor Author

@matheusandre1 you must sign your commits with -S.

Sorry, I always forget about that.

@fjtirado fjtirado left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matheusandre1
Lets make default event source a WorkflowValueResolver, so it returns an URI from the WorkflowContext, TaskContext and Model

Signed-off-by: Matheus André <matheusandr2@gmail.com>
public class EmitSourceResolver implements WorkflowValueResolver<URI> {

private static final String SEP = "/";
private static final String VER_SEP = ":";

@fjtirado fjtirado Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardozanini why a ":" and not a "/"

I think a calculated default source should combine applicationid and definition id and not use any other separator than /, so, in my opinion the code should be

workflow.definition().application().id()+SEP+workflow.definition().id().toString(SEP);

You can remove VER_SEP

private Optional<URITemplateResolver> templateResolver;
private Optional<FunctionReader> functionReader;
private URI defaultCatalogURI;
private WorkflowValueResolver<URI> defaultEventSource = new EmitSourceResolver();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be initialized only if withDefaultEventSource has not being invoked.

}

public Builder withDefaultEventSource(String defaultEventSource) {
return withDefaultEventSource(URI.create(defaultEventSource));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the string is not a valir URI, application initialization will fail. Im not sure we should have this method to be hones

Comment on lines +43 to +49
WorkflowApplication app =
WorkflowApplication.builder().withEventConsumer(broker).withEventPublisher(broker).build();
try {
app.workflowDefinition(wf).instance().start().join();
} finally {
app.close();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WorkflowApplication app =
WorkflowApplication.builder().withEventConsumer(broker).withEventPublisher(broker).build();
try {
app.workflowDefinition(wf).instance().start().join();
} finally {
app.close();
}
try (WorkflowApplication app =
WorkflowApplication.builder().withEventConsumer(broker).withEventPublisher(broker).build())
{
app.workflowDefinition(wf).instance().start().join();
}

Comment on lines +127 to +134
WorkflowApplication app =
WorkflowApplication.builder()
.withDefaultEventSource("app.source")
.withEventConsumer(broker)
.withEventPublisher(broker)
.build();
app.workflowDefinition(wf).instance().start().join();
app.close();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WorkflowApplication app =
WorkflowApplication.builder()
.withDefaultEventSource("app.source")
.withEventConsumer(broker)
.withEventPublisher(broker)
.build();
app.workflowDefinition(wf).instance().start().join();
app.close();
try (WorkflowApplication app =
WorkflowApplication.builder()
.withDefaultEventSource("app.source")
.withEventConsumer(broker)
.withEventPublisher(broker)
.build()) {
app.workflowDefinition(wf).instance().start().join();
}

Comment on lines +148 to +154
WorkflowApplication app =
WorkflowApplication.builder()
.withDefaultEventSource(
(workflow, task, model) -> URI.create("apps/" + workflow.definition().id().name()))
.withEventConsumer(broker)
.withEventPublisher(broker)
.build();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, apparently AI does not know about try {} existance

Comment on lines +40 to +42
List<CloudEvent> events = Collections.synchronizedList(new ArrayList<>());
InMemoryEvents broker = new InMemoryEvents();
broker.register(eventType, events::add);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of duplicated code in these test, lets avoid copy paste and use "@beforeeach" annotation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve CloudEvent defaults and validation for emit events

3 participants