How pool tagging works
mainPool tagging allows you to isolate traffic or use different configurations for the same {scheme, host, port} or Unix socket. You define tagged pools using Finch.Pool.new/2 in your configuration. When making a request, specify the :pool_tag option. If the specified tag does not exist in the configuration, Finch falls back to the :default configuration.
# Configuration with tagged pools
children = [
{Finch,
name: MyTaggedFinch,
pools: %{
Finch.Pool.new("https://api.example.com") => [size: 50, count: 4],
Finch.Pool.new("https://api.example.com", tag: :web) => [size: 20, count: 2],
Finch.Pool.new("http+unix:///tmp/api.sock", tag: :api) => [size: 30, count: 2],
Finch.Pool.new("http+unix:///tmp/api.sock", tag: :web) => [size: 10, count: 1],
:default => [size: 10, count: 1]
}}
}
]
# Making requests with tags
# Uses the :api tagged pool
request = Finch.build(:get, "https://api.example.com/users", [], nil, pool_tag: :api)
Finch.request(request, MyTaggedFinch)
# Uses the :web tagged pool
request = Finch.build(:get, "https://api.example.com/users", [], nil, pool_tag: :web)
Finch.request(request, MyTaggedFinch)
# Uses :default tag (or falls back to default config)
request = Finch.build(:get, "https://api.example.com/users")
Finch.request(request, MyTaggedFinch)
# Tagged Unix socket pool
request =
Finch.build(
:get,
"http://localhost/",
[],
nil,
unix_socket: "/tmp/api.sock",
pool_tag: :api
)
Finch.request(request, MyTaggedFinch)