92
92
% % The database stores the MQTT subscription options in the binding arguments for:
93
93
% % * v1 as Erlang record #mqtt_subscription_opts{}
94
94
% % * v2 as AMQP 0.9.1 table
95
- binding_args_v2 :: boolean ()
95
+ binding_args_v2 :: boolean (),
96
+ msg_interceptor_ctx :: rabbit_msg_interceptor :context ()
96
97
}).
97
98
98
99
-record (state ,
@@ -214,9 +215,15 @@ process_connect(
214
215
% % To simplify logic, we decide at connection establishment time to stick
215
216
% % with either binding args v1 or v2 for the lifetime of the connection.
216
217
BindingArgsV2 = rabbit_feature_flags :is_enabled ('rabbitmq_4.1.0' ),
218
+ ProtoVerAtom = proto_integer_to_atom (ProtoVer ),
219
+ MsgIcptCtx = #{protocol => ProtoVerAtom ,
220
+ vhost => VHost ,
221
+ username => Username ,
222
+ connection_name => ConnName ,
223
+ client_id => ClientId },
217
224
S = # state {
218
225
cfg = # cfg {socket = Socket ,
219
- proto_ver = proto_integer_to_atom ( ProtoVer ) ,
226
+ proto_ver = ProtoVerAtom ,
220
227
clean_start = CleanStart ,
221
228
session_expiry_interval_secs = SessionExpiry ,
222
229
ssl_login_name = SslLoginName ,
@@ -237,7 +244,8 @@ process_connect(
237
244
will_msg = WillMsg ,
238
245
max_packet_size_outbound = MaxPacketSize ,
239
246
topic_alias_maximum_outbound = TopicAliasMaxOutbound ,
240
- binding_args_v2 = BindingArgsV2 },
247
+ binding_args_v2 = BindingArgsV2 ,
248
+ msg_interceptor_ctx = MsgIcptCtx },
241
249
auth_state = # auth_state {
242
250
user = User ,
243
251
authz_ctx = AuthzCtx }},
@@ -1632,15 +1640,15 @@ publish_to_queues(
1632
1640
# state {cfg = # cfg {exchange = ExchangeName = # resource {name = ExchangeNameBin },
1633
1641
delivery_flow = Flow ,
1634
1642
conn_name = ConnName ,
1635
- trace_state = TraceState },
1643
+ trace_state = TraceState ,
1644
+ msg_interceptor_ctx = MsgIcptCtx },
1636
1645
auth_state = # auth_state {user = # user {username = Username }}} = State ) ->
1637
1646
Anns = #{? ANN_EXCHANGE => ExchangeNameBin ,
1638
1647
? ANN_ROUTING_KEYS => [mqtt_to_amqp (Topic )]},
1639
1648
Msg0 = mc :init (mc_mqtt , MqttMsg , Anns , mc_env ()),
1640
1649
case rabbit_exchange :lookup (ExchangeName ) of
1641
1650
{ok , Exchange } ->
1642
- Ctx = msg_interceptor_ctx (State ),
1643
- Msg = rabbit_msg_interceptor :intercept_incoming (Msg0 , Ctx ),
1651
+ Msg = rabbit_msg_interceptor :intercept_incoming (Msg0 , MsgIcptCtx ),
1644
1652
QNames0 = rabbit_exchange :route (Exchange , Msg , #{return_binding_keys => true }),
1645
1653
QNames = drop_local (QNames0 , State ),
1646
1654
rabbit_trace :tap_in (Msg , QNames , ConnName , Username , TraceState ),
@@ -2066,13 +2074,13 @@ deliver_to_client(Msgs, Ack, State) ->
2066
2074
end , State , Msgs ).
2067
2075
2068
2076
deliver_one_to_client ({QNameOrType , QPid , QMsgId , _Redelivered , Mc } = Delivery ,
2069
- AckRequired , State0 ) ->
2077
+ AckRequired ,
2078
+ # state {cfg = # cfg {msg_interceptor_ctx = MsgIcptCtx }} = State0 ) ->
2070
2079
SubscriberQoS = case AckRequired of
2071
2080
true -> ? QOS_1 ;
2072
2081
false -> ? QOS_0
2073
2082
end ,
2074
2083
McMqtt0 = mc :convert (mc_mqtt , Mc , mc_env ()),
2075
- MsgIcptCtx = msg_interceptor_ctx (State0 ),
2076
2084
McMqtt = rabbit_msg_interceptor :intercept_outgoing (McMqtt0 , MsgIcptCtx ),
2077
2085
MqttMsg = # mqtt_msg {qos = PublisherQos } = mc :protocol_state (McMqtt ),
2078
2086
QoS = effective_qos (PublisherQos , SubscriberQoS ),
@@ -2539,17 +2547,6 @@ message_redelivered(_, _, _) ->
2539
2547
is_success (ReasonCode ) ->
2540
2548
ReasonCode < ? RC_UNSPECIFIED_ERROR .
2541
2549
2542
- msg_interceptor_ctx (# state {cfg = # cfg {client_id = ClientId ,
2543
- conn_name = ConnName ,
2544
- vhost = VHost ,
2545
- proto_ver = ProtoVer },
2546
- auth_state = # auth_state {user = # user {username = Username }}}) ->
2547
- #{protocol => ProtoVer ,
2548
- vhost => VHost ,
2549
- username => Username ,
2550
- connection_name => ConnName ,
2551
- client_id => ClientId }.
2552
-
2553
2550
-spec format_status (state ()) -> map ().
2554
2551
format_status (
2555
2552
# state {queue_states = QState ,
0 commit comments