1 |
|
-module(mongoose_wpool_rabbit). |
2 |
|
-behaviour(mongoose_wpool). |
3 |
|
|
4 |
|
-export([init/0]). |
5 |
|
-export([start/4]). |
6 |
|
-export([stop/2]). |
7 |
|
|
8 |
|
-spec init() -> ok | {error, any()}. |
9 |
|
init() -> |
10 |
2 |
application:ensure_all_started(amqp_client). |
11 |
|
|
12 |
|
-spec start(mongooseim:host_type_or_global(), mongoose_wpool:tag(), |
13 |
|
mongoose_wpool:pool_opts(), mongoose_wpool:conn_opts()) -> {ok, pid()} | {error, any()}. |
14 |
|
start(HostType, Tag, WpoolOptsIn, ConnOpts) -> |
15 |
2 |
#{confirms_enabled := Confirms, max_worker_queue_len := MaxQueueLen} = ConnOpts, |
16 |
2 |
PoolName = mongoose_wpool:make_pool_name(rabbit, HostType, Tag), |
17 |
2 |
Worker = {mongoose_rabbit_worker, |
18 |
|
[{amqp_client_opts, mongoose_amqp:network_params(ConnOpts)}, |
19 |
|
{host_type, HostType}, |
20 |
|
{pool_tag, Tag}, |
21 |
|
{confirms, Confirms}, |
22 |
|
{max_queue_len, MaxQueueLen}]}, |
23 |
2 |
WpoolOpts = [{worker, Worker} | WpoolOptsIn], |
24 |
2 |
mongoose_wpool:start_sup_pool(rabbit, PoolName, WpoolOpts). |
25 |
|
|
26 |
|
-spec stop(mongooseim:host_type_or_global(), mongoose_wpool:tag()) -> ok. |
27 |
|
stop(_, _) -> |
28 |
2 |
ok. |