Skip to content

Sample code for Nexus messaging#135

Open
Evanthx wants to merge 4 commits intomainfrom
signals-nexus-dotnet
Open

Sample code for Nexus messaging#135
Evanthx wants to merge 4 commits intomainfrom
signals-nexus-dotnet

Conversation

@Evanthx
Copy link
Copy Markdown

@Evanthx Evanthx commented Apr 15, 2026

This is sample code to show two ways to send messages (signals, queries, and updates) through Nexus.

@Evanthx Evanthx requested a review from a team as a code owner April 15, 2026 18:35
}

[WorkflowSignal]
public async Task ApproveAsync(string name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Either should should return void (not sure if that's allowed for signal handlers) or the method should return Task.CompletedTask.

## Entity pattern

The handler worker starts a `GreetingWorkflow` for a user ID at boot time.
`NexusGreetingService` routes every Nexus operation to that existing workflow by deriving
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I noticed recently that we usually capitalized Workflow in docs. I think all Temporal primitives are title cased. Maybe we should do the same here to be consistent.

}
catch (Temporalio.Exceptions.RpcException ex)
{
logger.LogWarning(ex, "Could not start entity workflow, may already exist");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.LogWarning(ex, "Could not start entity workflow, may already exist");
logger.LogWarning(ex, "Could not start entity workflow");

If the workflow already exists, it should attach to the currently running workflow due to IdConflictPolicy = Temporalio.Api.Enums.V1.WorkflowIdConflictPolicy.UseExisting, correct?

implementation. This highlights that the same activity logic can be exposed through Nexus in different
ways depending on whether the caller needs lifecycle control.

See each directory's README for running instructions.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we link to those READMEs from here?

{
}

public Task<string> EnsureHandlerTaskQueueAsync() =>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this using a lazy initializer? What problem is it trying to solve that just running the lamba body directly doesn't consider?

@@ -0,0 +1,16 @@
This sample shows how to expose a long-running workflow's queries, updates, and signals as Nexus
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(CallerRemoteWorkflow wf) => wf.RunAsync(),
new(id: $"wf-{Guid.NewGuid()}", taskQueue: callerWorker.Options.TaskQueue!));

Assert.True(result.Length > 0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's assert the exact expected length and that each line in the result has the expected containment.

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.

2 participants