Provide a way to change actor Kind before connecting to a cluster
volkanalkilic opened this issue · 0 comments
volkanalkilic commented
I would like to request a feature that allows changing actor Kind before connecting to the cluster.
In some scenarios, an application can be a member of the cluster for different tasks. For example, let's say I have an edge application consisting of the same actors that collect data from devices in the network based on the parameters I send. When I install this application on different networks, each instance becomes a completely different application, not a replica.
In such cases, if there was a way to change the actor Kind before connecting to the cluster, I could parse the instances and send the parameters to the correct member.
Dirty solution I'm using right now:
- I converted
public const string Kind
in Proto.Cluster.CodeGen code template topublic static string Kind
. - I added a suffix to the Kind variable of all actors using reflection before connecting to the cluster.
public static void UpdateKindsWithSuffix(string suffix) {
var assembly = typeof(FieldbusWorkerActor).Assembly;
var messageTypes = assembly.GetTypes().Where(t => t.Namespace == "Proxus.Shared.Messages");
foreach (var messageType in messageTypes) {
var kindField = messageType.GetField("Kind", BindingFlags.Public | BindingFlags.Static);
if (kindField != null) {
var kindValue = (string) kindField.GetValue(null);
kindValue += "_" + suffix;
kindField.SetValue(null, kindValue);
}
}
}
- And finally:
Cluster().RequestAsync<object>(request.DeviceID,"ACTOR-KIND-WITH-SUFFIX",request, CancellationToken.None);