How to implement custom routing in Akka.Net

不羁岁月 提交于 2020-01-03 06:27:13

问题


Akka.Net provides a number of usefull routing strategies out of the box (we currently use smallest mailbox and consistent hashing), but what if want to implement custom router with strategy based on let's call it Worker Node Load Index which is will be calculated separetly on each node based on current resource consumption.

I could not find docs or examples regarding this topic, so any info is higly appreciated. Thanks


回答1:


You can create your own routing strategy by deriving from the base RoutingLogic class: https://github.com/akkadotnet/akka.net/blob/614f1f0e824384f065e7b72e827c1ff937eafca5/src/core/Akka/Routing/Router.cs#L166

Overall your class might look a bit like:

public class CustomRouter : RoutingLogic
{
    public override Routee Select(object message, Routee[] routees)
    {
        return routees.OrderBy(WorkerNodeLoadIndex).First();
    }

    private double WorkerNodeLoadIndex(Routee arg)
    {
        return 0.0; // put your real calculation here
    }
}


来源:https://stackoverflow.com/questions/39654665/how-to-implement-custom-routing-in-akka-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!