Repository navigation
5.5.2.1.12. Publish Event Action Node
A Publish Event Action Node generates one or more typed notifications and publishes them on behalf of a behavior. It is useful when other behaviors or client watchers should observe an event without choosing a single recipient.
Use the generic event overload to construct the notification; its outgoing control flow continues after publication:
public sealed record OrderDispatched(string OrderId);The following fragment belongs inside the relevant method or builder callback:
.AddPublishEventAction<OrderDispatched>(
"PublishDispatch",
async c => new OrderDispatched(
c.GetTokensOfType<string>().Single()),
node => node.AddControlFlow("Continue"))
.AddAction("Continue", async c =>
await audit.RecordAsync("dispatch-published", c.CancellationToken))The publish action does not return an application token to the local graph. Use Send Event Action Node for a directed send to one behavior, or Accept Event Action Node to handle an incoming event.
The optional builder callback exposes these settings:
| Method | Default | Meaning |
|---|---|---|
SetPublishScope(PublishScope scope) |
Self |
Publish on behalf of self, parent, owner, or combined flags. None disables publication. Missing parent/owner scopes are skipped. |
SetTimeToLive(int secondsToLive) |
0 |
Positive values limit notification lifetime. Zero disables history/retries unless retained. |
SetRetain(bool retain) |
false |
Keep only the latest retained notification of each declared type for queries and subscription retries. |
SetImmediatePublish(bool immediatePublish) |
false |
Publish during execution instead of waiting for the transactional call's commit. |
PublishScope is defined in Stateflows.Entities.Enums. Notification attributes continue to apply: a type-level TTL takes precedence over a TTL header, and [Retain]/[ImmediatePublish] enable their corresponding policies. Builder false settings do not negate those attributes.
A delegate can return Task<IEnumerable<TEvent>> to publish several notifications:
.AddPublishEventAction<OrderDispatched>(
"PublishDispatches",
async context => context.GetTokensOfType<string>()
.Select(id => new OrderDispatched(id)).ToArray(),
node => node.SetTimeToLive(300).AddControlFlow("Continue"))Typed implementations use GenerateEventsAsync() and can declare get-only static properties:
using Stateflows.Activities;
using Stateflows.Entities.Enums;
public sealed class PublishDispatches(IInputTokens<string> orderIds)
: IPublishEventActionNode<OrderDispatched>
{
public static PublishScope PublishScope => PublishScope.Self;
public static int TimeToLive => 300;
public static bool Retain => false;
public static bool ImmediatePublish => false;
public Task<IEnumerable<OrderDispatched>> GenerateEventsAsync()
=> Task.FromResult<IEnumerable<OrderDispatched>>(
orderIds.Select(id => new OrderDispatched(id)).ToArray());
}The interface's static defaults are Self, 0, false, and false. Both typed registration overloads read the node's settings first, then apply the builder callback:
.AddPublishEventAction<OrderDispatched, PublishDispatches>(node =>
node.SetTimeToLive(60).SetRetain(true))An explicit node name can also precede the callback. Generated sequences are materialized while the node's input context remains available. Retention keeps only the latest retained notification, not every element generated by the action; use positive TTL with Retain = false for history. See notification retention and requests.
Root output pins use this publication mechanism through OutputPinNode<TEvent> and expose the same builder settings.
During Activity streaming, streamed and mixed firings publish immediately without an explicit ImmediatePublish header. Observers can receive their notifications before the network's corresponding values and marking are checkpointed. Those publications cannot be retracted if the invocation or a later checkpoint fails.
Pure transactional firings normally buffer publications until their regular call commits and discard them if it fails; an explicit immediate-publication policy still applies. A regular publication commit is not a checkpoint of the whole live network. These rules also apply to context.Behavior.Publish(...) inside ordinary action callbacks.
Home page Support Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0. © by Mikołaj Milewski, 2026