Create & Manage Actors
This guide will walk through creating & managing Rivet Actors.
Actor tags
Tags are simple key-value pairs attached to every actor. Tags serve two purposes:
- Actor Discovery: Find specific actors using
client.get(tags, opts)
- Organization: Group actors for monitoring & administration purposes
When choosing tags, follow these best practices:
- Keep values short and concise
- Use consistent naming patterns
- Avoid storing sensitive information
The name
tag is required and specifies which type of actor to spawn.
Common tag patterns
The following examples show different ways tags can be used to organize actors:
Client
Clients are used to connect & manage actors.
To create a new client, write:
Tip
/* CONNECTION ADDRESS */
.client.get(tags, opts)
client.get(tags)
attempts to find an existing actor matching the provided tags. If no matching actor is found, it creates a new one with those tags.
client.create(opts)
To explicitly create a new actor, use client.create(tags)
. This will create a new actor with the provided tags.
client.getWithId(id, opts)
Each actor has a unique identifier that can be used instead of tags. To get an actor by its ID, use client.getWithId(id)
.
It's recommended to use tags instead of using actor IDs directly (e.g. see docId
above).
For example:
Options
opts.parameters
All client methods accept a parameters
property. This can be used to pass information about the current connection, such as authentication tokens or usernames.
For example:
This is available on client.get
, client.create
, and client.getWithId
.
Read more about parameters & connections here.
opts.create.tags
When creating an actor, you can specify additional tags beyond those used for querying. If opts.create.tags
is not provided, the query tags will be used. For example:
This is available on client.get
and client.create
.
opts.create.region
By default, actors are created in the region with the lowest latency for the client. You can override this by specifying create.region
:
This is available on client.get
and client.create
.
opts.noCreate
To prevent creating a new actor if it does not exist, pass the noCreate
option. For example:
This is available only on client.get
.
Shutdown actor
For security reasons, actors must be shut down from within the actor itself using this._shutdown()
. For example:
Read more about the actor lifecycle.