99-behaviour (cowboy_websocket ).
1010-behaviour (cowboy_sub_protocol ).
1111
12+ -include_lib (" kernel/include/logger.hrl" ).
13+ -include_lib (" rabbit_common/include/logging.hrl" ).
1214-include_lib (" rabbitmq_stomp/include/rabbit_stomp.hrl" ).
1315-include_lib (" rabbitmq_stomp/include/rabbit_stomp_frame.hrl" ).
1416-include_lib (" amqp_client/include/amqp_client.hrl" ).
4143 peername ,
4244 auth_hd ,
4345 stats_timer ,
44- connection
46+ connection ,
47+ should_use_fhc :: rabbit_types :option (boolean ())
4548}).
4649
50+ -define (APP , rabbitmq_web_stomp ).
51+
4752% % cowboy_sub_protcol
4853upgrade (Req , Env , Handler , HandlerState ) ->
4954 upgrade (Req , Env , Handler , HandlerState , #{}).
@@ -80,6 +85,11 @@ init(Req0, Opts) ->
8085 end ,
8186 WsOpts0 = proplists :get_value (ws_opts , Opts , #{}),
8287 WsOpts = maps :merge (#{compress => true }, WsOpts0 ),
88+ ShouldUseFHC = application :get_env (? APP , enable_file_handle_cache , true ),
89+ case ShouldUseFHC of
90+ true -> ? LOG_INFO (" Web STOMP: file handle cache use is enabled" );
91+ false -> ? LOG_INFO (" Web STOMP: file handle cache use is disabled" )
92+ end ,
8393 {? MODULE , Req , # state {
8494 frame_type = proplists :get_value (type , Opts , text ),
8595 heartbeat_sup = KeepaliveSup ,
@@ -89,11 +99,18 @@ init(Req0, Opts) ->
8999 conserve_resources = false ,
90100 socket = SockInfo ,
91101 peername = PeerAddr ,
92- auth_hd = cowboy_req :header (<<" authorization" >>, Req )
102+ auth_hd = cowboy_req :header (<<" authorization" >>, Req ),
103+ should_use_fhc = ShouldUseFHC
93104 }, WsOpts }.
94105
95- websocket_init (State ) ->
96- ok = file_handle_cache :obtain (),
106+ websocket_init (State = # state {should_use_fhc = ShouldUseFHC }) ->
107+ case ShouldUseFHC of
108+ true ->
109+ ok = file_handle_cache :obtain ();
110+ false -> ok ;
111+ undefined ->
112+ ok = file_handle_cache :obtain ()
113+ end ,
97114 process_flag (trap_exit , true ),
98115 {ok , ProcessorState } = init_processor_state (State ),
99116 {ok , rabbit_event :init_stats_timer (
@@ -314,9 +331,15 @@ maybe_block(State, _) ->
314331stop (State ) ->
315332 stop (State , 1000 , " STOMP died" ).
316333
317- stop (State = # state {proc_state = ProcState }, CloseCode , Error0 ) ->
334+ stop (State = # state {proc_state = ProcState , should_use_fhc = ShouldUseFHC }, CloseCode , Error0 ) ->
318335 maybe_emit_stats (State ),
319- ok = file_handle_cache :release (),
336+ case ShouldUseFHC of
337+ true ->
338+ ok = file_handle_cache :release ();
339+ false -> ok ;
340+ undefined ->
341+ ok = file_handle_cache :release ()
342+ end ,
320343 _ = rabbit_stomp_processor :flush_and_die (ProcState ),
321344 Error1 = rabbit_data_coercion :to_binary (Error0 ),
322345 {[{close , CloseCode , Error1 }], State }.
0 commit comments