跳转到内容
简体中文

Config seed provider

此内容尚不支持你的语言。

ConfigSeedProvider returns a static list of seed addresses — from a constructor argument or environment variables. No discovery logic; what you configure is what you get.

import { Cluster, ClusterOptions } from 'actor-ts/cluster';
import { ConfigSeedProvider, ConfigSeedProviderOptions } from 'actor-ts/discovery';
const configSeedProviderOptions = ConfigSeedProviderOptions.create()
.withSeeds(['10.0.0.5:2552']) // the designated first node, on every node
.withSystemName('my-app');
const provider = new ConfigSeedProvider(
configSeedProviderOptions,
);
const seeds = await provider.lookup();
const clusterOptions = ClusterOptions.create()
.withHost(host)
.withPort(port)
.withSeeds(seeds);
await Cluster.join(system, clusterOptions);

The simplest provider for the simplest case.

Give every node the same list, naming the designated first node by the address it advertises. On that node the list resolves to itself, which the join drops — Cluster.bootstrap filters the resolved addresses and Cluster.join filters its seeds — so it is left with nobody to dial and forms the cluster; every other node dials it. One list, correct everywhere.

A list naming every node is the shape that does not work: after self-exclusion nobody is left with an empty list, nobody may form the cluster, and every node waits in joining for a promotion that never comes — see the symmetric seed list does not cold-start. Only the bootstrap’s stable observation, an election among the listed nodes, breaks that tie. The same holds for the list under actor-ts.discovery.config.seeds, which is this provider in config form.

type ConfigSeedProviderOptionsType = {
seeds: string[]; // "system@host:port" or "host:port"
systemName: string; // default system name for seeds omitting it
};

Two ways to specify:

// Explicit:
const configSeedProviderOptions = ConfigSeedProviderOptions.create()
.withSeeds(['10.0.0.5:2552'])
.withSystemName('my-app');
new ConfigSeedProvider(
configSeedProviderOptions,
);
// From env (CSV):
seedsFromEnv('ACTOR_TS_SEEDS', 'my-app');
// where ACTOR_TS_SEEDS='10.0.0.5:2552' — more entries only with stable observation

Pick whichever fits your deployment pattern. Env vars are typical for containerized deployments where the list comes from a config map / orchestrator.

Three good fits:

  1. Docker Compose — known service names + ports; actor-ts-1:2552 in every service’s environment, the designated first node.
  2. VMs with fixed IPs — three production VMs, each with a stable address.
  3. Tests — known peer addresses inline in test setup.