scopeName static method
Distinguishes a name this isolate registers with an external system.
Every MessageBroker that identifies its client by name needs this,
and none of them can be made correct by the framework: the broker builds
the name, so the framework never sees it. An app with AppConfig.workers
above 1 runs the same AppConfig.createBroker override in every isolate,
so a broker that passes its configured name through untouched has every
worker claiming to be the same consumer — and on a broker that tracks
unacknowledged work per consumer, each worker's pending messages become
invisible to the others. That is the failure this exists to prevent, and
a broker that does not call this still has it.
MyBroker({String consumerName = 'my-service'})
: consumerName = IsolateIdentity.scopeName(consumerName);
The parent (index 0) is deliberately left alone. Suffixing it too
would be tidier, and it would also rename the consumer of every app that
upgrades: a single-worker deployment goes from orders to orders-0,
and anything still pending under the old name is stranded, because
nothing reads that name again. Leaving the parent untouched means an
upgrade changes nothing for the apps that never spawn workers, and only
the newly added worker isolates take names that never existed before.
The asymmetry is the point.
Reads current, so it is only meaningful once the generated server file
has set the identity — which it does before any application code runs.
Called earlier, or in a test, it returns name unchanged, which is the
truthful answer for one isolate.
Implementation
static String scopeName(String name) {
final index = current.index;
return index == 0 ? name : '$name-$index';
}