@@ -63,18 +63,19 @@ handle_http_req(<<"GET">>,
6363 _ConnPid ) ->
6464 QNameBin = uri_string :unquote (QNameBinQuoted ),
6565 QName = rabbit_misc :r (Vhost , queue , QNameBin ),
66- case rabbit_amqqueue :lookup (QName ) of
67- {ok , Q } ->
68- {ok , NumMsgs , NumConsumers } = rabbit_amqqueue :stat (Q ),
69- RespPayload = encode_queue (Q , NumMsgs , NumConsumers ),
70- {<<" 200" >>, RespPayload };
66+ case rabbit_amqqueue :with (
67+ QName ,
68+ fun (Q ) ->
69+ {ok , NumMsgs , NumConsumers } = rabbit_amqqueue :stat (Q ),
70+ RespPayload = encode_queue (Q , NumMsgs , NumConsumers ),
71+ {ok , {<<" 200" >>, RespPayload }}
72+ end ) of
73+ {ok , Result } ->
74+ Result ;
7175 {error , not_found } ->
72- case rabbit_amqqueue :not_found_or_absent_dirty (QName ) of
73- not_found ->
74- throw (<<" 404" >>, " ~ts not found" , [rabbit_misc :rs (QName )]);
75- {absent , Q , Reason } ->
76- absent (Q , Reason )
77- end
76+ throw (<<" 404" >>, " ~ts not found" , [rabbit_misc :rs (QName )]);
77+ {error , {absent , Q , Reason }} ->
78+ absent (Q , Reason )
7879 end ;
7980
8081handle_http_req (HttpMethod = <<" PUT" >>,
@@ -107,44 +108,47 @@ handle_http_req(HttpMethod = <<"PUT">>,
107108 rabbit_core_metrics :queue_declared (QName ),
108109
109110 {Q1 , NumMsgs , NumConsumers , StatusCode } =
110- case rabbit_amqqueue :lookup (QName ) of
111- {ok , Q } ->
112- try rabbit_amqqueue :assert_equivalence (
113- Q , Durable , AutoDelete , QArgs , Owner ) of
114- ok ->
115- {ok , Msgs , Consumers } = rabbit_amqqueue :stat (Q ),
116- {Q , Msgs , Consumers , <<" 200" >>}
117- catch exit :# amqp_error {name = precondition_failed ,
118- explanation = Expl } ->
119- throw (<<" 409" >>, Expl , [])
120- end ;
111+ case rabbit_amqqueue :with (
112+ QName ,
113+ fun (Q ) ->
114+ try rabbit_amqqueue :assert_equivalence (
115+ Q , Durable , AutoDelete , QArgs , Owner ) of
116+ ok ->
117+ {ok , Msgs , Consumers } = rabbit_amqqueue :stat (Q ),
118+ {ok , {Q , Msgs , Consumers , <<" 200" >>}}
119+ catch exit :# amqp_error {name = precondition_failed ,
120+ explanation = Expl } ->
121+ throw (<<" 409" >>, Expl , []);
122+ exit :# amqp_error {explanation = Expl } ->
123+ throw (<<" 400" >>, Expl , [])
124+ end
125+ end ) of
126+ {ok , Result } ->
127+ Result ;
121128 {error , not_found } ->
122- case rabbit_amqqueue :not_found_or_absent_dirty (QName ) of
123- not_found ->
124- ok = check_vhost_queue_limit (QName ),
125- ok = check_dead_letter_exchange (QName , QArgs , User ),
126- case rabbit_amqqueue :declare (
127- QName , Durable , AutoDelete , QArgs , Owner , Username ) of
128- {new , Q } ->
129- rabbit_core_metrics :queue_created (QName ),
130- {Q , 0 , 0 , <<" 201" >>};
131- {absent , Q , Reason } ->
132- absent (Q , Reason );
133- {existing , _Q } ->
134- % % Must have been created in the meantime. Loop around again.
135- handle_http_req (HttpMethod , PathSegments , Query ,
136- ReqPayload , Vhost , User , ConnPid );
137- {owner_died , Q } ->
138- % % Presumably our own days are numbered since the
139- % % connection has died. Pretend the queue exists though,
140- % % just so nothing fails.
141- {Q , 0 , 0 , <<" 201" >>};
142- {protocol_error , _ErrorType , Reason , ReasonArgs } ->
143- throw (<<" 400" >>, Reason , ReasonArgs )
144- end ;
129+ ok = check_vhost_queue_limit (QName ),
130+ ok = check_dead_letter_exchange (QName , QArgs , User ),
131+ case rabbit_amqqueue :declare (
132+ QName , Durable , AutoDelete , QArgs , Owner , Username ) of
133+ {new , Q } ->
134+ rabbit_core_metrics :queue_created (QName ),
135+ {Q , 0 , 0 , <<" 201" >>};
136+ {owner_died , Q } ->
137+ % % Presumably our own days are numbered since the
138+ % % connection has died. Pretend the queue exists though,
139+ % % just so nothing fails.
140+ {Q , 0 , 0 , <<" 201" >>};
145141 {absent , Q , Reason } ->
146- absent (Q , Reason )
147- end
142+ absent (Q , Reason );
143+ {existing , _Q } ->
144+ % % Must have been created in the meantime. Loop around again.
145+ handle_http_req (HttpMethod , PathSegments , Query ,
146+ ReqPayload , Vhost , User , ConnPid );
147+ {protocol_error , _ErrorType , Reason , ReasonArgs } ->
148+ throw (<<" 400" >>, Reason , ReasonArgs )
149+ end ;
150+ {error , {absent , Q , Reason }} ->
151+ absent (Q , Reason )
148152 end ,
149153
150154 RespPayload = encode_queue (Q1 , NumMsgs , NumConsumers ),
0 commit comments