@@ -246,15 +246,6 @@ process_request(?PUBACK,
246
246
{ok , State }
247
247
end ;
248
248
249
- process_request (? PUBLISH ,
250
- Packet = # mqtt_packet {
251
- fixed = Fixed = # mqtt_packet_fixed {qos = ? QOS_2 }},
252
- State ) ->
253
- % Downgrade QOS_2 to QOS_1
254
- process_request (? PUBLISH ,
255
- Packet # mqtt_packet {
256
- fixed = Fixed # mqtt_packet_fixed {qos = ? QOS_1 }},
257
- State );
258
249
process_request (? PUBLISH ,
259
250
# mqtt_packet {
260
251
fixed = # mqtt_packet_fixed {qos = Qos ,
@@ -266,11 +257,12 @@ process_request(?PUBLISH,
266
257
State0 = # state {unacked_client_pubs = U ,
267
258
cfg = # cfg {retainer_pid = RPid ,
268
259
proto_ver = ProtoVer }}) ->
260
+ EffectiveQos = maybe_downgrade_qos (Qos ),
269
261
rabbit_global_counters :messages_received (ProtoVer , 1 ),
270
262
State = maybe_increment_publisher (State0 ),
271
263
Publish = fun () ->
272
264
Msg = # mqtt_msg {retain = Retain ,
273
- qos = Qos ,
265
+ qos = EffectiveQos ,
274
266
topic = Topic ,
275
267
dup = Dup ,
276
268
packet_id = PacketId ,
@@ -288,8 +280,10 @@ process_request(?PUBLISH,
288
280
Error
289
281
end
290
282
end ,
291
- case Qos of
292
- N when N > ? QOS_0 ->
283
+ case EffectiveQos of
284
+ ? QOS_0 ->
285
+ publish_to_queues_with_checks (Topic , Publish , State );
286
+ ? QOS_1 ->
293
287
rabbit_global_counters :messages_received_confirm (ProtoVer , 1 ),
294
288
case rabbit_mqtt_confirms :contains (PacketId , U ) of
295
289
false ->
@@ -299,9 +293,7 @@ process_request(?PUBLISH,
299
293
% % We already sent this message to target queues awaiting confirmations.
300
294
% % Hence, we ignore this re-send.
301
295
{ok , State }
302
- end ;
303
- _ ->
304
- publish_to_queues_with_checks (Topic , Publish , State )
296
+ end
305
297
end ;
306
298
307
299
process_request (? SUBSCRIBE ,
@@ -322,7 +314,7 @@ process_request(?SUBSCRIBE,
322
314
(# mqtt_topic {name = TopicName ,
323
315
qos = TopicQos },
324
316
{L , S0 }) ->
325
- QoS = supported_sub_qos (TopicQos ),
317
+ QoS = maybe_downgrade_qos (TopicQos ),
326
318
maybe
327
319
ok ?= maybe_replace_old_sub (TopicName , QoS , S0 ),
328
320
{ok , Q } ?= ensure_queue (QoS , S0 ),
@@ -663,16 +655,23 @@ maybe_send_retained_message(RPid, #mqtt_topic{name = Topic0, qos = SubscribeQos}
663
655
State
664
656
end .
665
657
666
- make_will_msg (# mqtt_packet_connect {will_flag = false }) ->
658
+ make_will_msg (# mqtt_packet_connect {will_flag = false }) ->
667
659
undefined ;
668
- make_will_msg (# mqtt_packet_connect {will_retain = Retain ,
669
- will_qos = Qos ,
670
- will_topic = Topic ,
671
- will_msg = Msg }) ->
672
- # mqtt_msg {retain = Retain ,
673
- qos = Qos ,
674
- topic = Topic ,
675
- dup = false ,
660
+ make_will_msg (# mqtt_packet_connect {will_flag = true ,
661
+ will_retain = Retain ,
662
+ will_qos = Qos ,
663
+ will_topic = Topic ,
664
+ will_msg = Msg }) ->
665
+ EffectiveQos = maybe_downgrade_qos (Qos ),
666
+ Correlation = case EffectiveQos of
667
+ ? QOS_0 -> undefined ;
668
+ ? QOS_1 -> ? WILL_MSG_QOS_1_CORRELATION
669
+ end ,
670
+ # mqtt_msg {retain = Retain ,
671
+ qos = EffectiveQos ,
672
+ packet_id = Correlation ,
673
+ topic = Topic ,
674
+ dup = false ,
676
675
payload = Msg }.
677
676
678
677
check_vhost_exists (VHost , Username , PeerIp ) ->
@@ -885,14 +884,14 @@ creds(User, Pass, SSLLoginName) ->
885
884
auth_attempt_failed (PeerIp , Username ) ->
886
885
rabbit_core_metrics :auth_attempt_failed (PeerIp , Username , mqtt ).
887
886
888
- supported_sub_qos (? QOS_0 ) -> ? QOS_0 ;
889
- supported_sub_qos (? QOS_1 ) -> ? QOS_1 ;
890
- supported_sub_qos (? QOS_2 ) -> ? QOS_1 .
891
-
892
887
delivery_mode (? QOS_0 ) -> 1 ;
893
888
delivery_mode (? QOS_1 ) -> 2 ;
894
889
delivery_mode (? QOS_2 ) -> 2 .
895
890
891
+ maybe_downgrade_qos (? QOS_0 ) -> ? QOS_0 ;
892
+ maybe_downgrade_qos (? QOS_1 ) -> ? QOS_1 ;
893
+ maybe_downgrade_qos (? QOS_2 ) -> ? QOS_1 .
894
+
896
895
ensure_queue (QoS , State = # state {auth_state = # auth_state {user = # user {username = Username }}}) ->
897
896
case get_queue (QoS , State ) of
898
897
{ok , Q } ->
@@ -1155,9 +1154,9 @@ process_routing_confirm(#delivery{confirm = false},
1155
1154
rabbit_global_counters :messages_unroutable_dropped (ProtoVer , 1 ),
1156
1155
State ;
1157
1156
process_routing_confirm (# delivery {confirm = true ,
1158
- msg_seq_no = undefined },
1157
+ msg_seq_no = ? WILL_MSG_QOS_1_CORRELATION },
1159
1158
[], State = # state {cfg = # cfg {proto_ver = ProtoVer }}) ->
1160
- % % unroutable will message with QoS > 0
1159
+ % % unroutable will message with QoS 1
1161
1160
rabbit_global_counters :messages_unroutable_dropped (ProtoVer , 1 ),
1162
1161
State ;
1163
1162
process_routing_confirm (# delivery {confirm = true ,
@@ -1172,8 +1171,8 @@ process_routing_confirm(#delivery{confirm = true,
1172
1171
process_routing_confirm (# delivery {confirm = false }, _ , State ) ->
1173
1172
State ;
1174
1173
process_routing_confirm (# delivery {confirm = true ,
1175
- msg_seq_no = undefined }, [_ |_ ], State ) ->
1176
- % % routable will message with QoS > 0
1174
+ msg_seq_no = ? WILL_MSG_QOS_1_CORRELATION }, [_ |_ ], State ) ->
1175
+ % % routable will message with QoS 1
1177
1176
State ;
1178
1177
process_routing_confirm (# delivery {confirm = true ,
1179
1178
msg_seq_no = PktId },
0 commit comments