如何在使用Hocon时指定HashMapping

时间:2016-09-03 12:01:54

标签: f# akka.net hocon

如果HOCON路由器下面有consitent-hashing-pool,我该如何指定hashMapping。

    akka {
      actor {
        serializers {
          wire = "Akka.Serialization.WireSerializer, Akka.Serialization.Wire"
        }
        serialization-bindings {
          "System.Object" = wire
        }
        deployment {
          /data-collector {
            router = consistent-hashing-pool
            nr-of-instances = 10
          }
        }
      }
      loggers = ["Akka.Logger.NLog.NLogLogger,Akka.Logger.NLog"]
    }

鉴于

let config = Configuration.load()
let systemName = config.GetString("app-config.actorsystem", "my-system")
let system = System.create systemName config
let collectorRouter = 
  let hashMapping (msg:obj) =
    match msg with
    | :? Message as msg ->
        match msg with
        | Parse (_, req) -> req.uniqueId |> box
    | _ -> "-" |> box
  ConsistentHashingPool (10, ConsistentHashMapping hashMapping)
let dataCollectorProps = 
  { props (dataCollector settings.collector) with
      Router = Some (collectorRouter :> RouterConfig)} //(FromConfig.Instance.WithFallback collectorRouter)
let test = spawn system "data-collector" <| dataCollectorProps

Router = Some (collectorRouter :> RouterConfig)工作

Router = Some (FromConfig.Instance.WithFallback collectorRouter)

指定hashMapping函数的正确方法是什么?

修改1 来自控制台的警告是

Akka.Routing.ConsistentHashingRoutingLogic|Message [Message] must be handled by hashMapping, or implement [IConsistentHashable] or be wrapped in [ConsistentHashableEnvelope]

1 个答案:

答案 0 :(得分:0)

three ways of specifying the hash key。我最喜欢的是实现IConsistentHashable并从ConsistentHashKey属性返回密钥(基于消息的某些属性)。

my Consistent Hashing article的示例摘录(在C#中;抱歉,我不知道F#):

public class CurrencyPriceChangeMessage : IConsistentHashable
{
    public string CurrencyPair { get; }
    public decimal Price { get; }

    public object ConsistentHashKey
    {
        get
        {
            return this.CurrencyPair;
        }
    }

散列密钥将用于将具有相同密钥的消息始终路由到同一个路由器。