Skip to content

Commit

Permalink
Add new advanced docs page on manual sharding
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed May 24, 2024
1 parent 59224cf commit fefb642
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions guides/advanced/manual_sharding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Manual Sharding

Advanced users can use methods located in the `Nostrum.Shard.Supervisor` module
to manually connect shards to the gateway as well as initiate manual disconnect
and reconnects (attempting to `RESUME` sessions where possible).

You can set the `num_shards` option in your `nostrum` application config to
`:manual` to prevent Nostrum from automatically starting shards. You should use
the methods in the shard supervisor such as `Nostrum.Shard.Supervisor.connect/2`
to manually start shards if using this configuration option.

## Reconnection example

```elixir
# On Node A
iex> Nostrum.Shard.Supervisor.connect(0, 1)
iex> resume_info = Nostrum.Shard.Supervisor.disconnect(0)
%{shard_num: 0, ...}

# On another node
iex> Nostrum.Shard.Supervisor.reconnect(resume_info)
```

Discord will perform a best effort attempt to resume the gateway from the time
of disconnection, relaying any missed events. Note that this can result in some
events being missed or some events being delivered twice.
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ defmodule Nostrum.Mixfile do
"guides/advanced/multi_node.md",
"guides/advanced/hot_code_upgrade.md",
"guides/advanced/gateway_compression.md",
"guides/advanced/manual_sharding.md",
"guides/cheat-sheets/api.cheatmd",
"guides/cheat-sheets/qlc.cheatmd",
"guides/cheat-sheets/voice.cheatmd"
Expand Down

0 comments on commit fefb642

Please sign in to comment.