RabbitMQ 启动(bootsteps)
RabbitMQ对待启动这件事是很认真的,通过把启动步骤描述成DAG,然后拓扑排序依次启动。
之所以‘小题大做’,因为RabbitMQ的模块非常多,模块之间的依赖关系强。
bootsteps之DAG节点
requires描述前驱节点。
enables描述后继节点。
-rabbit_boot_step({codec_correctness_check, [{description, "codec correctness check"}, {mfa, {rabbit_binary_generator, check_empty_frame_size, []}}, {requires, pre_boot}, {enables, external_infrastructure}]}).
上图:
dot代码
dot命令
dot -Tpng "rabbit_boot.gv" > "/home/max/Code/rabbit_boot.png"
把-rabbit_boot_step属性全部拷贝到rabbit_attribute.erl文件,然后一条erlang命令搞定
lists:foreach(fun({A, B}) -> io:format("~s \-> ~s;~n", [A, B]) end ,[{KK, proplists:get_value(enables, V)} || {K, [{KK, V}]} <- rabbit_attribute:module_info(attributes), K =:= rabbit_boot_step, proplists:get_value(enables, V) =/= undefined]).
dot代码
digraph G { pre_boot [shape=doublecircle, style=filled,color=black,fillcolor=green; pre_boot -> codec_correctness_check; file_handle_cache -> database; database -> database_sync; pre_boot -> file_handle_cache; pre_boot -> worker_pool; external_infrastructure -> rabbit_registry; external_infrastructure -> rabbit_event; external_infrastructure -> kernel_ready; kernel_ready -> rabbit_alarm; rabbit_alarm -> rabbit_memory_monitor; kernel_ready -> guid_generator; kernel_ready -> delegate_sup; rabbit_alarm -> rabbit_node_monitor; guid_generator -> rabbit_node_monitor; kernel_ready -> core_initialized; core_initialized -> recovery; recovery -> mirrored_queues; core_initialized -> routing_ready; routing_ready -> log_relay; log_relay -> direct_client; log_relay -> networking; networking -> notify_cluster; background_gc; edge [style="dashed", color="blue"]; codec_correctness_check -> external_infrastructure; database -> external_infrastructure; database_sync -> external_infrastructure; file_handle_cache -> worker_pool; worker_pool -> external_infrastructure; rabbit_registry -> kernel_ready; rabbit_event -> kernel_ready; rabbit_alarm -> core_initialized; rabbit_memory_monitor -> core_initialized; guid_generator -> core_initialized; delegate_sup -> core_initialized; rabbit_node_monitor -> core_initialized; empty_db_check -> routing_ready; recovery -> routing_ready; mirrored_queues -> routing_ready; log_relay -> networking; background_gc -> networking; }