|
|
@@ -16,8 +16,10 @@
|
|
|
).
|
|
|
|
|
|
-define(DESC_NOT_FOUND, <<"Queue not found">>).
|
|
|
--define(RESP_NOT_FOUND,
|
|
|
- {404, #{code => <<"NOT_FOUND">>, message => ?DESC_NOT_FOUND}}
|
|
|
+-define(DESC_DISABLED, <<"Feature is disabled">>).
|
|
|
+-define(RESP_NOT_FOUND, ?RESP_NOT_FOUND(?DESC_NOT_FOUND)).
|
|
|
+-define(RESP_NOT_FOUND(MSG),
|
|
|
+ {404, #{code => <<"NOT_FOUND">>, message => MSG}}
|
|
|
).
|
|
|
|
|
|
-define(DESC_CREATE_CONFICT, <<"Queue with given group name and topic filter already exists">>).
|
|
|
@@ -55,13 +57,21 @@
|
|
|
'/durable_queues/:id'/2
|
|
|
]).
|
|
|
|
|
|
+%% Internal exports
|
|
|
+-export([
|
|
|
+ check_enabled/2
|
|
|
+]).
|
|
|
+
|
|
|
-import(hoconsc, [mk/2, ref/1, ref/2]).
|
|
|
-import(emqx_dashboard_swagger, [error_codes/2]).
|
|
|
|
|
|
namespace() -> "durable_queues".
|
|
|
|
|
|
api_spec() ->
|
|
|
- emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).
|
|
|
+ emqx_dashboard_swagger:spec(?MODULE, #{
|
|
|
+ check_schema => true,
|
|
|
+ filter => fun ?MODULE:check_enabled/2
|
|
|
+ }).
|
|
|
|
|
|
paths() ->
|
|
|
[
|
|
|
@@ -82,7 +92,8 @@ schema("/durable_queues") ->
|
|
|
],
|
|
|
responses => #{
|
|
|
200 => resp_list_durable_queues(),
|
|
|
- 400 => error_codes(['BAD_REQUEST'], ?DESC_BAD_REQUEST)
|
|
|
+ 400 => error_codes(['BAD_REQUEST'], ?DESC_BAD_REQUEST),
|
|
|
+ 404 => error_codes(['NOT_FOUND'], ?DESC_DISABLED)
|
|
|
}
|
|
|
},
|
|
|
post => #{
|
|
|
@@ -92,7 +103,8 @@ schema("/durable_queues") ->
|
|
|
'requestBody' => durable_queue_post(),
|
|
|
responses => #{
|
|
|
201 => resp_create_durable_queue(),
|
|
|
- 409 => error_codes(['CONFLICT'], ?DESC_CREATE_CONFICT)
|
|
|
+ 409 => error_codes(['CONFLICT'], ?DESC_CREATE_CONFICT),
|
|
|
+ 404 => error_codes(['NOT_FOUND'], ?DESC_DISABLED)
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -125,6 +137,12 @@ schema("/durable_queues/:id") ->
|
|
|
}
|
|
|
}.
|
|
|
|
|
|
+check_enabled(Request, _ReqMeta) ->
|
|
|
+ case emqx_ds_shared_sub_config:enabled() of
|
|
|
+ true -> {ok, Request};
|
|
|
+ false -> ?RESP_NOT_FOUND(<<"Durable queues are disabled">>)
|
|
|
+ end.
|
|
|
+
|
|
|
'/durable_queues'(get, #{query_string := QString}) ->
|
|
|
Cursor = maps:get(<<"cursor">>, QString, undefined),
|
|
|
Limit = maps:get(<<"limit">>, QString),
|