diff options
author | Alvaro Videla <videlalvaro@gmail.com> | 2013-10-12 14:14:58 -0500 |
---|---|---|
committer | Alvaro Videla <videlalvaro@gmail.com> | 2013-10-12 14:14:58 -0500 |
commit | d1a4535f7d9ec3555be99722ce67149ac98fd66f (patch) | |
tree | feac3657613cd7727abe60cc79aa265136989c32 | |
parent | b725d82cd5be0dbb7f8fe8c7f516d3853ecb79ff (diff) | |
download | rabbitmq-server-bug25818.tar.gz |
adds rabbit_queue_arguments behavior plus implementationbug25818
-rw-r--r-- | src/rabbit_amqqueue.erl | 46 | ||||
-rw-r--r-- | src/rabbit_amqqueue_arguments.erl | 83 | ||||
-rw-r--r-- | src/rabbit_queue_arguments.erl | 59 | ||||
-rw-r--r-- | src/rabbit_registry.erl | 3 |
4 files changed, 149 insertions, 42 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 8a84c9f4..d1529a16 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -41,8 +41,6 @@ -include("rabbit.hrl"). -include_lib("stdlib/include/qlc.hrl"). --define(INTEGER_ARG_TYPES, [byte, short, signedint, long]). - -define(MORE_CONSUMER_CREDIT_AFTER, 50). -define(FAILOVER_WAIT_MILLIS, 100). @@ -422,47 +420,13 @@ check_arguments(QueueName, Args, Validators) -> end || {Key, Fun} <- Validators], ok. -declare_args() -> - [{<<"x-expires">>, fun check_expires_arg/2}, - {<<"x-message-ttl">>, fun check_message_ttl_arg/2}, - {<<"x-dead-letter-routing-key">>, fun check_dlxrk_arg/2}, - {<<"x-max-length">>, fun check_max_length_arg/2}]. - -consume_args() -> [{<<"x-priority">>, fun check_int_arg/2}]. +declare_args() -> arguments_list('declare_args'). -check_int_arg({Type, _}, _) -> - case lists:member(Type, ?INTEGER_ARG_TYPES) of - true -> ok; - false -> {error, {unacceptable_type, Type}} - end. - -check_max_length_arg({Type, Val}, Args) -> - case check_int_arg({Type, Val}, Args) of - ok when Val >= 0 -> ok; - ok -> {error, {value_negative, Val}}; - Error -> Error - end. - -check_expires_arg({Type, Val}, Args) -> - case check_int_arg({Type, Val}, Args) of - ok when Val == 0 -> {error, {value_zero, Val}}; - ok -> rabbit_misc:check_expiry(Val); - Error -> Error - end. - -check_message_ttl_arg({Type, Val}, Args) -> - case check_int_arg({Type, Val}, Args) of - ok -> rabbit_misc:check_expiry(Val); - Error -> Error - end. +consume_args() -> arguments_list('consume_args'). -check_dlxrk_arg({longstr, _}, Args) -> - case rabbit_misc:table_lookup(Args, <<"x-dead-letter-exchange">>) of - undefined -> {error, routing_key_but_no_dlx_defined}; - _ -> ok - end; -check_dlxrk_arg({Type, _}, _Args) -> - {error, {unacceptable_type, Type}}. +arguments_list(Method) -> + lists:append([QAM:arguments(Method) || + QAM <- rabbit_queue_arguments:select(Method)]). list() -> mnesia:dirty_match_object(rabbit_queue, #amqqueue{_ = '_'}). diff --git a/src/rabbit_amqqueue_arguments.erl b/src/rabbit_amqqueue_arguments.erl new file mode 100644 index 00000000..370a027d --- /dev/null +++ b/src/rabbit_amqqueue_arguments.erl @@ -0,0 +1,83 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2007-2013 GoPivotal, Inc. All rights reserved. +%% + +-module(rabbit_amqqueue_arguments). + +-behaviour(rabbit_queue_arguments). + +-export([description/0, arguments/1, applies_to/1]). + +-define(INTEGER_ARG_TYPES, [byte, short, signedint, long]). + +-rabbit_boot_step({?MODULE, + [{description, "amqqueue arguments"}, + {mfa, {rabbit_registry, register, + [queue_arguments, <<"amqqueue arguments">>, ?MODULE]}}, + {requires, rabbit_registry}, + {enables, recovery}]}). + +description() -> + [{description, <<"AMQ Queue Declare/Consume Arguments">>}]. + +arguments('declare_args') -> + [{<<"x-expires">>, fun check_expires_arg/2}, + {<<"x-message-ttl">>, fun check_message_ttl_arg/2}, + {<<"x-dead-letter-routing-key">>, fun check_dlxrk_arg/2}, + {<<"x-max-length">>, fun check_max_length_arg/2}]; + +arguments('consume_args') -> [{<<"x-priority">>, fun check_int_arg/2}]; + +arguments(_Other) -> []. + +applies_to('declare_args') -> true; +applies_to('consume_args') -> true; +applies_to(_Other) -> false. + +%%---------------------------------------------------------------------------- + +check_int_arg({Type, _}, _) -> + case lists:member(Type, ?INTEGER_ARG_TYPES) of + true -> ok; + false -> {error, {unacceptable_type, Type}} + end. + +check_max_length_arg({Type, Val}, Args) -> + case check_int_arg({Type, Val}, Args) of + ok when Val >= 0 -> ok; + ok -> {error, {value_negative, Val}}; + Error -> Error + end. + +check_expires_arg({Type, Val}, Args) -> + case check_int_arg({Type, Val}, Args) of + ok when Val == 0 -> {error, {value_zero, Val}}; + ok -> rabbit_misc:check_expiry(Val); + Error -> Error + end. + +check_message_ttl_arg({Type, Val}, Args) -> + case check_int_arg({Type, Val}, Args) of + ok -> rabbit_misc:check_expiry(Val); + Error -> Error + end. + +check_dlxrk_arg({longstr, _}, Args) -> + case rabbit_misc:table_lookup(Args, <<"x-dead-letter-exchange">>) of + undefined -> {error, routing_key_but_no_dlx_defined}; + _ -> ok + end; +check_dlxrk_arg({Type, _}, _Args) -> + {error, {unacceptable_type, Type}}.
\ No newline at end of file diff --git a/src/rabbit_queue_arguments.erl b/src/rabbit_queue_arguments.erl new file mode 100644 index 00000000..a1ce3631 --- /dev/null +++ b/src/rabbit_queue_arguments.erl @@ -0,0 +1,59 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2007-2013 GoPivotal, Inc. All rights reserved. +%% + +-module(rabbit_queue_arguments). + +-include("rabbit.hrl"). + +-export([select/1]). + +%% TODO: docs + +-ifdef(use_specs). + +-type(validator_fun() :: fun((any(), rabbit_framing:amqp_table()) -> + rabbit_types:ok_or_error({atom(), any()}))). +-type(argument() :: {binary(), validator_fun()}). + +-type(argument_set() :: 'declare_args' | + 'consume_args'). + +-callback description() -> [proplists:property()]. + +-callback arguments(argument_set()) -> [argument()]. + +-callback applies_to(argument_set()) -> boolean(). + +-else. + +-export([behaviour_info/1]). + +behaviour_info(callbacks) -> + [{description, 0}, {arguments, 1}, {applies_to, 1}]; +behaviour_info(_Other) -> + undefined. + +-endif. + +%%---------------------------------------------------------------------------- + +%% select the interceptors that apply to intercept_method(). +select(Method) -> [QA || QA <- filter(list()), QA:applies_to(Method)]. + +filter(Modules) -> + [M || M <- Modules, code:which(M) =/= non_existing]. + +list() -> [M || {_, M} <- rabbit_registry:lookup_all(queue_arguments)].
\ No newline at end of file diff --git a/src/rabbit_registry.erl b/src/rabbit_registry.erl index 3014aeb7..f3818b7c 100644 --- a/src/rabbit_registry.erl +++ b/src/rabbit_registry.erl @@ -132,7 +132,8 @@ class_module(runtime_parameter) -> rabbit_runtime_parameter; class_module(exchange_decorator) -> rabbit_exchange_decorator; class_module(queue_decorator) -> rabbit_queue_decorator; class_module(policy_validator) -> rabbit_policy_validator; -class_module(ha_mode) -> rabbit_mirror_queue_mode. +class_module(ha_mode) -> rabbit_mirror_queue_mode; +class_module(queue_arguments) -> rabbit_queue_arguments. %%--------------------------------------------------------------------------- |