2017-04-25 80 views
0

是否可以在註冊表(或Registry在elixir 1.4中)註冊一個:poolboy池後啓動?在註冊表中註冊一個poolboy池

我需要在池上的pub/sub體系結構上實現某種功能。我想在同一個別名下注冊多個池。

Registry:duplicate,並:gproc:p,但看起來他們沒有與:via元組的作品,所以我不能在我的游泳池name使用它。

回答

4

它看起來像Registry只允許註冊當前進程下的一個給定的名稱。

所以要使用註冊表,您需要啓動一個進程以充當每個Poolboy池的代理,例如GenServer模塊PoolProxy

defmodule PoolProxy do 
    use GenServer 

    def init(poolname) do 
    {:ok, _} = Registry.register(Registry.PoolPubSub, "PoolPubSub", nil) 
    {:ok, poolname} 
    end 

    def handle_call(:notify_pool, _from, poolname) do 
    # interact with poolboy pool here... 
    end 
end 

註冊後,就可以發佈 - 訂閱到代理進程,與

Registry.dispatch(Registry.PoolPubSub, "PoolPubSub", fn entries -> 
    for {pid, _} <- entries, do: GenServer.call(pid, :notify_pool) 
end)