Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 20, 2025

Fixes #[issue_number]

Summary

This PR addresses confusion in the Orleans Broadcast Channels documentation by adding missing code snippets, clarifying key concepts, and providing a comprehensive comparison with Orleans Streams.

Changes Made

Added Missing Code Snippets

The documentation now includes two critical code snippets that were previously referenced but not shown:

  1. ILiveStockGrain interface - Shows that the grain uses IGrainWithGuidKey, clarifying the grain's key type
  2. ChannelNames class - Displays the static class containing the channel name constant used throughout the example

Enhanced Publisher Section

Added detailed explanations for the StockWorker publisher code:

  • ChannelId.Create parameters: Clarified that Guid.Empty is used as the namespace parameter to indicate a single shared broadcast where all subscribers receive all messages
  • Channel name duplication: Explained why ChannelNames.LiveStockTicker appears in both GetBroadcastChannelProvider and ChannelId.Create, and that both must match the name used in silo configuration
  • Producer-consumer relationship: Clarified that the producer doesn't know about specific consumer grains—it publishes to the channel and all implicitly subscribed grains automatically receive messages

Enhanced Consumer Section

Improved the consumer grain explanation:

  • Implicit subscriptions: Explained that implementing IOnBroadcastChannelSubscribed enables automatic subscription when grains are activated
  • OnSubscribed timing: Clarified that this method is called automatically when the grain is activated (first use or after recovery from failure)
  • [ImplicitChannelSubscription] attribute: Highlighted this attribute's role in marking grains for automatic subscription

Added Comparison with Orleans Streams

Created a new section comparing Broadcast Channels with Orleans Streams (including in-memory streams):

  • Comparison table: Eight key features compared side-by-side (subscription model, persistence, delivery guarantees, use cases, etc.)
  • When to use broadcast channels: Five scenarios where broadcast channels are the better choice
  • When to use streams: Six scenarios where streams are more appropriate

Validation

  • ✅ Markdown linting passes (markdownlint-cli2)
  • ✅ All code snippets compile successfully
  • ✅ Follows .NET documentation writing style guidelines
  • ✅ Added ai-usage: ai-assisted frontmatter as required

Related Issue

This PR addresses all points raised in the issue:

  • Explains Guid.Empty usage in ChannelId.Create
  • Shows the ChannelNames class source
  • Shows the ILiveStockGrain interface declaration
  • Clarifies the relationship between subscription in the grain and producer in the background service
  • Explains when OnSubscribed is called
  • Clarifies why the channel name appears twice
  • Provides comprehensive comparison between Broadcast Channels and Streams

cc @ReubenBond @IEvangelist

Original prompt

This section details on the original issue you should resolve

<issue_title>Orleans Broadcast Channels - Relationship between publisher and consumer is unclear</issue_title>
<issue_description>### Type of issue

Missing information

Description

I am having a hard time trying to understand broadcast channels from the documentation.

One main source of confusion is this line of code in StockWorker:

ChannelId channelId = ChannelId.Create(ChannelNames.LiveStockTicker, Guid.Empty);
  • There's no explanation of why Guid.Empty is used. Is Guid.Empty the key of the consuming grain? The declaration of ILiveStockGrain is not in the docs, so it's unclear what the grain's key type is. There's also no code showing how the grain reference was created, so again unclear as to what the key is.
  • It's not clear where ChannelNames comes from, is it a static class not shown in the docs?
  • The grain doesn't use ChannelNames.LiveStockTicker, so what's the relationship here between subscription in the grain, and producer in the background service?
  • One of the bullet points states The OnSubscribed method is called when the grain subscribes to the broadcast channel. It would be good to call out when this is. I assume it's when the grain is activated, and the grain then subscribes 'under-the-hood' due to the mechanism being implicit?
  • This may be a quirk of the API, but in the StockWorker constructor, ChannelNames.LiveStockTicker is used to get the channel provider, so why does it need to also be specified as part of ChannelId.Create?

A comparison between Broadcast Channels and Streams (probably in-memory streams as they seem similar to broadcast channels) would be great, as I'm not sure when to use one over the other and the pros and cons.

/cc @ReubenBond

Clarifications to the docs might also help close dotnet/orleans#8292

Page URL

https://learn.microsoft.com/en-us/dotnet/orleans/streaming/broadcast-channel

Content source URL

https://github.com/dotnet/docs/blob/main/docs/orleans/streaming/broadcast-channel.md

Document Version Independent Id

7de240a6-146f-48d8-c652-58f0ff3571db

Article author

@IEvangelist

Metadata

  • ID: e43e2b09-a8fa-e0fa-99a6-42f7d927e106
  • Service: dotnet-orleans</issue_description>

<agent_instructions>Please work on this issue, considering all comments and issue descriptions.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #39496


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/orleans/streaming/broadcast-channel.md docs/orleans/streaming/broadcast-channel

Copilot AI changed the title [WIP] Add clarity to Orleans Broadcast Channels documentation Clarify Orleans Broadcast Channels documentation with missing context and comparisons Oct 20, 2025
Copilot finished work on behalf of IEvangelist October 20, 2025 15:40
Copilot AI requested a review from IEvangelist October 20, 2025 15:40
Copy link
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

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

LGTM

@IEvangelist IEvangelist marked this pull request as ready for review October 20, 2025 18:13
@Copilot Copilot AI review requested due to automatic review settings October 20, 2025 18:13
@IEvangelist IEvangelist requested a review from a team as a code owner October 20, 2025 18:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the Orleans Broadcast Channels documentation by clarifying previously unclear concepts and adding missing code examples. The changes address confusion about the relationship between publishers and consumers, the purpose of key parameters, and when to use broadcast channels versus streams.

Key Changes:

  • Added missing code snippets for ILiveStockGrain interface and ChannelNames class
  • Enhanced explanations of publisher and consumer behavior with detailed parameter descriptions
  • Added comprehensive comparison table between Broadcast Channels and Orleans Streams

Copilot finished work on behalf of IEvangelist October 20, 2025 18:21
Copilot AI requested a review from IEvangelist October 20, 2025 18:21
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This LGTM. Let's :shipit:

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.

Orleans Broadcast Channels - Relationship between publisher and consumer is unclear Broadcast and ChannelId

3 participants