diff options
| author | Matthias Radestock <matthias@lshift.net> | 2009-07-01 13:43:18 +0100 |
|---|---|---|
| committer | Matthias Radestock <matthias@lshift.net> | 2009-07-01 13:43:18 +0100 |
| commit | 0d611f1188edc7b8f9da7935e21865fb49163a14 (patch) | |
| tree | 9f7925f6078b1240e05f55d4dba8b5fc95b5ef76 | |
| parent | da5a1fd5b839d2ccbf83f17d618aae2184731ece (diff) | |
| parent | d87dab3eaa2d7e88a3be2fd8d724a36d6fa63144 (diff) | |
| download | rabbitmq-server-git-0d611f1188edc7b8f9da7935e21865fb49163a14.tar.gz | |
merge bug21060 into default
| -rw-r--r-- | src/rabbit_basic.erl | 57 | ||||
| -rw-r--r-- | src/rabbit_error_logger.erl | 10 |
2 files changed, 54 insertions, 13 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl index 761b3863b4..2dc619c1fb 100644 --- a/src/rabbit_basic.erl +++ b/src/rabbit_basic.erl @@ -33,17 +33,26 @@ -include("rabbit.hrl"). -include("rabbit_framing.hrl"). --export([publish/1, message/4, delivery/4]). +-export([publish/1, message/4, properties/1, delivery/4]). +-export([publish/4, publish/7]). %%---------------------------------------------------------------------------- -ifdef(use_specs). --spec(publish/1 :: (delivery()) -> - {ok, routing_result(), [pid()]} | not_found()). +-type(properties_input() :: (amqp_properties() | [{atom(), any()}])). +-type(publish_result() :: ({ok, routing_result(), [pid()]} | not_found())). + +-spec(publish/1 :: (delivery()) -> publish_result()). -spec(delivery/4 :: (bool(), bool(), maybe(txn()), message()) -> delivery()). --spec(message/4 :: (exchange_name(), routing_key(), binary(), binary()) -> - message()). +-spec(message/4 :: (exchange_name(), routing_key(), properties_input(), + binary()) -> message()). +-spec(properties/1 :: (properties_input()) -> amqp_properties()). +-spec(publish/4 :: (exchange_name(), routing_key(), properties_input(), + binary()) -> publish_result()). +-spec(publish/7 :: (exchange_name(), routing_key(), bool(), bool(), + maybe(txn()), properties_input(), binary()) -> + publish_result()). -endif. @@ -63,13 +72,47 @@ delivery(Mandatory, Immediate, Txn, Message) -> #delivery{mandatory = Mandatory, immediate = Immediate, txn = Txn, sender = self(), message = Message}. -message(ExchangeName, RoutingKeyBin, ContentTypeBin, BodyBin) -> +message(ExchangeName, RoutingKeyBin, RawProperties, BodyBin) -> + Properties = properties(RawProperties), {ClassId, _MethodId} = rabbit_framing:method_id('basic.publish'), Content = #content{class_id = ClassId, - properties = #'P_basic'{content_type = ContentTypeBin}, + properties = Properties, properties_bin = none, payload_fragments_rev = [BodyBin]}, #basic_message{exchange_name = ExchangeName, routing_key = RoutingKeyBin, content = Content, persistent_key = none}. + +properties(P = #'P_basic'{}) -> + P; +properties(P) when is_list(P) -> + %% Yes, this is O(length(P) * record_info(size, 'P_basic') / 2), + %% i.e. slow. Use the definition of 'P_basic' directly if + %% possible! + lists:foldl(fun ({Key, Value}, Acc) -> + case indexof(record_info(fields, 'P_basic'), Key) of + 0 -> throw({unknown_basic_property, Key}); + N -> setelement(N + 1, Acc, Value) + end + end, #'P_basic'{}, P). + +indexof(L, Element) -> indexof(L, Element, 1). + +indexof([], _Element, _N) -> 0; +indexof([Element | _Rest], Element, N) -> N; +indexof([_ | Rest], Element, N) -> indexof(Rest, Element, N + 1). + +%% Convenience function, for avoiding round-trips in calls across the +%% erlang distributed network. +publish(ExchangeName, RoutingKeyBin, Properties, BodyBin) -> + publish(ExchangeName, RoutingKeyBin, false, false, none, Properties, + BodyBin). + +%% Convenience function, for avoiding round-trips in calls across the +%% erlang distributed network. +publish(ExchangeName, RoutingKeyBin, Mandatory, Immediate, Txn, Properties, + BodyBin) -> + publish(delivery(Mandatory, Immediate, Txn, + message(ExchangeName, RoutingKeyBin, + properties(Properties), BodyBin))). diff --git a/src/rabbit_error_logger.erl b/src/rabbit_error_logger.erl index 76016a8cb2..b28574b707 100644 --- a/src/rabbit_error_logger.erl +++ b/src/rabbit_error_logger.erl @@ -31,6 +31,7 @@ -module(rabbit_error_logger). -include("rabbit.hrl"). +-include("rabbit_framing.hrl"). -define(LOG_EXCH_NAME, <<"amq.rabbitmq.log">>). @@ -75,10 +76,7 @@ publish(_Other, _Format, _Data, _State) -> publish1(RoutingKey, Format, Data, LogExch) -> {ok, _RoutingRes, _DeliveredQPids} = - rabbit_basic:publish( - rabbit_basic:delivery( - false, false, none, - rabbit_basic:message( - LogExch, RoutingKey, <<"text/plain">>, - list_to_binary(io_lib:format(Format, Data))))), + rabbit_basic:publish(LogExch, RoutingKey, false, false, none, + #'P_basic'{content_type = <<"text/plain">>}, + list_to_binary(io_lib:format(Format, Data))), ok. |
