diff options
author | Loïc Hoguin <[email protected]> | 2017-10-03 15:50:36 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-10-03 15:50:36 +0200 |
commit | 5cb08c35580023b91091c93f9a1f9198e35055c2 (patch) | |
tree | fcac3159b52e14db41d5f1d1b19f5d8530cc0d74 /docs/en/ranch/1.4/guide/embedded.asciidoc | |
parent | 35bc482f0be143abd728a228e937984dc5f6cc73 (diff) | |
download | ninenines.eu-5cb08c35580023b91091c93f9a1f9198e35055c2.tar.gz ninenines.eu-5cb08c35580023b91091c93f9a1f9198e35055c2.tar.bz2 ninenines.eu-5cb08c35580023b91091c93f9a1f9198e35055c2.zip |
Fix some links and add Ranch 1.4 docs
They were mistakenly labeled as 1.3. Sorry!
Diffstat (limited to 'docs/en/ranch/1.4/guide/embedded.asciidoc')
-rw-r--r-- | docs/en/ranch/1.4/guide/embedded.asciidoc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/docs/en/ranch/1.4/guide/embedded.asciidoc b/docs/en/ranch/1.4/guide/embedded.asciidoc new file mode 100644 index 00000000..55c018b1 --- /dev/null +++ b/docs/en/ranch/1.4/guide/embedded.asciidoc @@ -0,0 +1,48 @@ +== Embedded mode + +Embedded mode allows you to insert Ranch listeners directly +in your supervision tree. This allows for greater fault tolerance +control by permitting the shutdown of a listener due to the +failure of another part of the application and vice versa. + +=== Embedding + +To embed Ranch in your application you can simply add the child specs +to your supervision tree. This can all be done in the `init/1` function +of one of your application supervisors. + +Ranch requires at the minimum two kinds of child specs for embedding. +First, you need to add `ranch_sup` to your supervision tree, only once, +regardless of the number of listeners you will use. Then you need to +add the child specs for each listener. + +Ranch has a convenience function for getting the listeners child specs +called `ranch:child_spec/5`, that works like `ranch:start_listener/5`, +except that it doesn't start anything, it only returns child specs. + +As for `ranch_sup`, the child spec is simple enough to not require a +convenience function. + +The following example adds both `ranch_sup` and one listener to another +application's supervision tree. + +.Embed Ranch directly in your supervision tree + +[source,erlang] +---- +init([]) -> + RanchSupSpec = {ranch_sup, {ranch_sup, start_link, []}, + permanent, 5000, supervisor, [ranch_sup]}, + ListenerSpec = ranch:child_spec(echo, 100, + ranch_tcp, [{port, 5555}], + echo_protocol, [] + ), + {ok, {{one_for_one, 10, 10}, [RanchSupSpec, ListenerSpec]}}. +---- + +Remember, you can add as many listener child specs as needed, but only +one `ranch_sup` spec! + +It is recommended that your architecture makes sure that all listeners +are restarted if `ranch_sup` fails. See the Ranch internals chapter for +more details on how Ranch does it. |