1818-include (" rabbit.hrl" ).
1919-include (" rabbit_framing.hrl" ).
2020
21- -export ([publish /1 , message / 3 , message / 4 , properties / 1 , delivery / 4 ]).
22- - export ([ publish / 4 , publish / 6 ]).
21+ -export ([publish /4 , publish / 6 , publish / 1 ,
22+ message / 3 , message / 4 , properties / 1 , delivery / 4 ]).
2323-export ([build_content /2 , from_content /1 ]).
2424
2525% %----------------------------------------------------------------------------
3535-type (exchange_input () :: (rabbit_types :exchange () | rabbit_exchange :name ())).
3636-type (body_input () :: (binary () | [binary ()])).
3737
38+ -spec (publish / 4 ::
39+ (exchange_input (), rabbit_router :routing_key (), properties_input (),
40+ body_input ()) -> publish_result ()).
41+ -spec (publish / 6 ::
42+ (exchange_input (), rabbit_router :routing_key (), boolean (), boolean (),
43+ properties_input (), body_input ()) -> publish_result ()).
3844-spec (publish / 1 ::
3945 (rabbit_types :delivery ()) -> publish_result ()).
4046-spec (delivery / 4 ::
4955 rabbit_types :ok_or_error2 (rabbit_types :message (), any ())).
5056-spec (properties / 1 ::
5157 (properties_input ()) -> rabbit_framing :amqp_property_record ()).
52- -spec (publish / 4 ::
53- (exchange_input (), rabbit_router :routing_key (), properties_input (),
54- body_input ()) -> publish_result ()).
55- -spec (publish / 6 ::
56- (exchange_input (), rabbit_router :routing_key (), boolean (), boolean (),
57- properties_input (), body_input ()) -> publish_result ()).
5858-spec (build_content / 2 :: (rabbit_framing :amqp_property_record (),
5959 binary () | [binary ()]) -> rabbit_types :content ()).
6060-spec (from_content / 1 :: (rabbit_types :content ()) ->
6464
6565% %----------------------------------------------------------------------------
6666
67+ % % Convenience function, for avoiding round-trips in calls across the
68+ % % erlang distributed network.
69+ publish (Exchange , RoutingKeyBin , Properties , Body ) ->
70+ publish (Exchange , RoutingKeyBin , false , false , Properties , Body ).
71+
72+ % % Convenience function, for avoiding round-trips in calls across the
73+ % % erlang distributed network.
74+ publish (X = # exchange {name = XName }, RKey , Mandatory , Immediate , Props , Body ) ->
75+ publish (X , delivery (Mandatory , Immediate ,
76+ message (XName , RKey , properties (Props ), Body ),
77+ undefined ));
78+ publish (XName , RKey , Mandatory , Immediate , Props , Body ) ->
79+ publish (delivery (Mandatory , Immediate ,
80+ message (XName , RKey , properties (Props ), Body ),
81+ undefined )).
82+
6783publish (Delivery = # delivery {
68- message = # basic_message {exchange_name = ExchangeName }}) ->
69- case rabbit_exchange :lookup (ExchangeName ) of
84+ message = # basic_message {exchange_name = XName }}) ->
85+ case rabbit_exchange :lookup (XName ) of
7086 {ok , X } -> publish (X , Delivery );
71- Other -> Other
87+ Err -> Err
7288 end .
7389
90+ publish (X , Delivery ) ->
91+ {RoutingRes , DeliveredQPids } =
92+ rabbit_router :deliver (rabbit_exchange :route (X , Delivery ), Delivery ),
93+ {ok , RoutingRes , DeliveredQPids }.
94+
7495delivery (Mandatory , Immediate , Message , MsgSeqNo ) ->
7596 # delivery {mandatory = Mandatory , immediate = Immediate , sender = self (),
7697 message = Message , msg_seq_no = MsgSeqNo }.
@@ -113,11 +134,10 @@ strip_header(#content{properties = Props = #'P_basic'{headers = Headers}}
113134 headers = Headers0 }})
114135 end .
115136
116- message (ExchangeName , RoutingKey ,
117- # content {properties = Props } = DecodedContent ) ->
137+ message (XName , RoutingKey , # content {properties = Props } = DecodedContent ) ->
118138 try
119139 {ok , # basic_message {
120- exchange_name = ExchangeName ,
140+ exchange_name = XName ,
121141 content = strip_header (DecodedContent , ? DELETED_HEADER ),
122142 id = rabbit_guid :guid (),
123143 is_persistent = is_message_persistent (DecodedContent ),
@@ -127,10 +147,10 @@ message(ExchangeName, RoutingKey,
127147 {error , _Reason } = Error -> Error
128148 end .
129149
130- message (ExchangeName , RoutingKey , RawProperties , Body ) ->
150+ message (XName , RoutingKey , RawProperties , Body ) ->
131151 Properties = properties (RawProperties ),
132152 Content = build_content (Properties , Body ),
133- {ok , Msg } = message (ExchangeName , RoutingKey , Content ),
153+ {ok , Msg } = message (XName , RoutingKey , Content ),
134154 Msg .
135155
136156properties (P = # 'P_basic' {}) ->
@@ -152,28 +172,6 @@ indexof([], _Element, _N) -> 0;
152172indexof ([Element | _Rest ], Element , N ) -> N ;
153173indexof ([_ | Rest ], Element , N ) -> indexof (Rest , Element , N + 1 ).
154174
155- % % Convenience function, for avoiding round-trips in calls across the
156- % % erlang distributed network.
157- publish (Exchange , RoutingKeyBin , Properties , Body ) ->
158- publish (Exchange , RoutingKeyBin , false , false , Properties , Body ).
159-
160- % % Convenience function, for avoiding round-trips in calls across the
161- % % erlang distributed network.
162- publish (X = # exchange {name = XName }, RKey , Mandatory , Immediate , Props , Body ) ->
163- publish (X , delivery (Mandatory , Immediate ,
164- message (XName , RKey , properties (Props ), Body ),
165- undefined ));
166- publish (XName , RKey , Mandatory , Immediate , Props , Body ) ->
167- case rabbit_exchange :lookup (XName ) of
168- {ok , X } -> publish (X , RKey , Mandatory , Immediate , Props , Body );
169- Err -> Err
170- end .
171-
172- publish (X , Delivery ) ->
173- {RoutingRes , DeliveredQPids } =
174- rabbit_router :deliver (rabbit_exchange :route (X , Delivery ), Delivery ),
175- {ok , RoutingRes , DeliveredQPids }.
176-
177175is_message_persistent (# content {properties = # 'P_basic' {
178176 delivery_mode = Mode }}) ->
179177 case Mode of
0 commit comments