Aaronontheweb on dev
Fix #4083 - Endpoint receive bu… (compare)
Aaronontheweb on dev
Convert to ImmutableHashSet for… (compare)
Ok got rid of the ask pattern and instead used a message scheduler to time out. here is the new code and config on the sender side:
CODE:
//Attempt to get a list of supervisors from the SupervisorRegistry
SupervisorRegistryGetListRequest request = new SupervisorRegistryGetListRequest(Self);
_SupervisorRegistry.Tell(request);
var timeout = Context.System.Scheduler.ScheduleTellOnceCancelable(1000, Self, new SupervisorRegistryGetListEvent(request, null, false), Self);
Receive<SupervisorRegistryGetListEvent>(e => {
if(e.Success)
{
_logger.Info("{0} Received supervisor list.", Self.Path.ToStringWithAddress());
timeout.Cancel();
// Save the list for internal use
_AreaToSupervisorActor = e.ResponseGetList.SupervisorDictionary;
_logger.Debug("Actor {0} is Initialized, moving to Ready state.", _ActorType);
Become(Ready);
}
else
{
_logger.Warning("{0} Cannot retrieve list of supervisors. Unable to initialize. {1} retries.", Self.Path.ToStringWithAddress(), _FetchSupervisorListReties);
// retry the request and increase the timeout
_FetchSupervisorListReties++;
// Set up the timeout
timeout = Context.System.Scheduler.ScheduleTellOnceCancelable(1000*_FetchSupervisorListReties, Self, new SupervisorRegistryGetListEvent(request, null, false), Self);
// Send the request again
_SupervisorRegistry.Tell(request);
}
and the config on the sender side:
akka {
# here we are configuring log levels
log-config-on-start = off
stdout-loglevel = DEBUG
loglevel = DEBUG
// Define an Nlog logger for the Akka system
loggers = ["Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog"]
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
}
remote {
log-remote-lifecycle-events = DEBUG
log-received-messages = on
helios.tcp {
hostname = "127.0.0.1"
port = 8777
}
}
private void HandleGetListRequest(SupervisorRegistryGetListRequest r)
{
ImmutableDictionary<MicroServices.Area,IActorRef> immutableDictOfSupervisorsActors =
_KnownSupervisorsActors.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.SupervisorActorReference);
Sender.Tell(new SupervisorRegistryGetListResponse(r.Requestor,immutableDictOfSupervisorsActors,r));
}
akka {
# here we are configuring log levels
log-config-on-start = off
stdout-loglevel = DEBUG
loglevel = DEBUG
// Define an Nlog logger for the Akka system
loggers = ["Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog"]
// Enables connectivity to the remote ActorSystemBridge
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
}
remote {
helios.tcp {
port = 8888
hostname = "127.0.0.1"
}
}
}
@Horusiath I took out the cluster
Ok got rid of the ask pattern and instead used a message scheduler to time out. here is the new code and config on the sender side:
CODE
//Attempt to get a list of supervisors from the SupervisorRegistry
SupervisorRegistryGetListRequest request = new SupervisorRegistryGetListRequest(Self);
_SupervisorRegistry.Tell(request);
var timeout = Context.System.Scheduler.ScheduleTellOnceCancelable(1000, Self, new SupervisorRegistryGetListEvent(request, null, false), Self);
Receive<SupervisorRegistryGetListEvent>(e => {
if(e.Success)
{
_logger.Info("{0} Received supervisor list.", Self.Path.ToStringWithAddress());
timeout.Cancel();
// Save the list for internal use
_AreaToSupervisorActor = e.ResponseGetList.SupervisorDictionary;
_logger.Debug("Actor {0} is Initialized, moving to Ready state.", _ActorType);
Become(Ready);
}
else
{
_logger.Warning("{0} Cannot retrieve list of supervisors. Unable to initialize. {1} retries.", Self.Path.ToStringWithAddress(), _FetchSupervisorListReties);
// retry the request and increase the timeout
_FetchSupervisorListReties++;
// Set up the timeout
timeout = Context.System.Scheduler.ScheduleTellOnceCancelable(1000*_FetchSupervisorListReties, Self, new SupervisorRegistryGetListEvent(request, null, false), Self);
// Send the request again
_SupervisorRegistry.Tell(request);
}
and the config on the sender side:
akka {
# here we are configuring log levels
log-config-on-start = off
stdout-loglevel = DEBUG
loglevel = DEBUG
// Define an Nlog logger for the Akka system
loggers = ["Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog"]
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
}
remote {
log-remote-lifecycle-events = DEBUG
log-received-messages = on
helios.tcp {
hostname = "127.0.0.1"
port = 8777
}
}
To handle remote disconnection I did something like this
signalRSelection = Context.ActorSelection("akka.tcp://api@127.0.0.1:4545/user/signalr");
signalRSelection.Tell(message);
So, I am forcing a Context.ActorSelection before tell. I am thinking this should work although there could be performance issue.
However, this doesn't seems to work all the time. (It works the first time the remote disconnected).
Anyway to do this kind of if(disconneted){ connect(); }
?
(I am aware the watch for Terminated method. However, I have trouble finding the right time to ActorSelection again, because the remote could be still not available. )
akka {
persistence {
journal {
sql-server {
class = "Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer"
plugin-dispatcher = "akka.actor.default-dispatcher"
connection-string = "Data Source=(local);Initial Catalog=HelloClusterSharding;Integrated Security=SSPI"
connection-timeout = 30s
schema-name = Sharding
table-name = EventJournal
auto-initialize = on
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
metadata-table-name = Metadata
}
}
}
}
this works..
I'm trying to use a different sql server persistence for cluster sharding.
I have my sharding config set up like this:
cluster {
sharding {
least-shard-allocation-strategy.rebalance-threshold = 3
journal-plugin-id = "akka.persistence.journal.sql-server"
snapshot-plugin-id = "akka.persistence.snapshot-store.sql-server"
}
}
but I would like to replace the "sql-server" name with, let's say "sql-server-sharding"