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

Add Member Roles doc #5742

Merged
merged 23 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
47 changes: 47 additions & 0 deletions docs/articles/clustering/member-roles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
uid: member-roles
title: Member Roles
---

# Why Are Roles Important
Copy link
Member

Choose a reason for hiding this comment

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

Title: Member Roles


A cluster can have multiple Akka.NET applications in it, "roles" help to distinguish different Akka.NET applications within a cluster!
Copy link
Member

Choose a reason for hiding this comment

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

Diagram would be useful here


# How Can Roles Help

Not all Akka.NET applications in a cluster need to perform the same function. For example, there might be one sub-set which runs the web front-end, one which runs the data access layer and one for the number-crunching.
Choosing which actors to start on each node, for example cluster-aware routers, can take member roles into account to achieve this distribution of responsibilities.
Copy link
Member

Choose a reason for hiding this comment

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

Something needs to be said about usage of roles being a best practice. There isn't a good reason not to do it. Just come out and say this along the following lines:

  1. Roles make it very easy to direct traffic to the right areas in your cluster;
  2. Even if you only have a single type of node in your cluster, you should still use roles for it so you can leverage this infrastructure as your cluster expands in the future; and
  3. They add zero overhead in any conceivable way.


# Usage
Copy link
Member

Choose a reason for hiding this comment

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

Move this to right after your opening sentence in the document, drop the #Usage


The member roles are defined in the configuration property named `akka.cluster.roles`:

```
akka {
cluster {
roles = ["backend"]
}
}
```

and typically defined in the start script as a system property or environment variable.

```
var settings = ClusterShardingSettings
Copy link
Member

Choose a reason for hiding this comment

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

Wrong thing. This is showing how roles can be consumed from Akka.Cluster sharding. Has nothing to do with how they're defined in Akka.Cluster.

.Create(_system)
.WithRole(Environment.GetEnvironmentVariable("ROLE"));
```

The roles are part of the membership information in `MemberEvent` that you can subscribe to. The roles of the local cluster member are available from the `SelfMember` and that can be used for conditionally starting certain actors:
Copy link
Member

Choose a reason for hiding this comment

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

## How to Use Role Information in Akka.NET

### Programming Against Akka.Cluster Events

{rest of your language here}

### Akka.Cluster.Sharding

{example}

### `DistributedPubSub`

{example}

### `DData`

Copy link
Member

Choose a reason for hiding this comment

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

ClusterSingleton would be good too.


```csharp
var selfMember = Cluster.Get(_actorSystem).SelfMember;
if (selfMember.HasRole("backend"))
{
context.ActorOf(Backend.Prop(), "back");
}
else if (selfMember.HasRole("front"))
{
context.ActorOf(Frontend.Prop(), "front");
}
```
4 changes: 3 additions & 1 deletion docs/articles/clustering/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
- name: Distributed Data
href: distributed-data.md
- name: Split Brain Resolver
href: split-brain-resolver.md
href: split-brain-resolver.md
- name: Member Roles
Copy link
Member

Choose a reason for hiding this comment

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

Move this much closer to the top - as this is a critical, fundamental concept to clustering.

Also, link to this page from the cluster overview early on.

href: member-roles.md