twilight-gateway
twilight-gateway
is an implementation of Discord's sharding gateway sessions.
This is responsible for receiving stateful events in real-time from Discord and
sending some stateful information.
The primary type is the Shard
, a stateful interface to maintain a Websocket
connection to Discord's gateway. Much of its functionality can be configured,
and it's used to receive gateway events or raw Websocket messages, useful for
load balancing and microservices.
Multiple shards may easily be created at once, with a per shard config created
from a Fn(ShardId, ConfigBuilder) -> Config
closure, with the help of the
create_
set of functions. These functions will reuse shards' TLS context and
[session queue][queue], something otherwise achieved by cloning an existing
[Config
].
Features
simd-json
: usesimd-json
instead ofserde_json
for deserializing events- TLS (mutually exclusive)
native-tls
: platform's native TLS implementation vianative-tls
rustls-native-roots
(default):rustls
using native root certificatesrustls-webpki-roots
:rustls
usingwebpki-roots
for root certificates, useful forscratch
containers
twilight-http
(default): enable thestream::create_recommended
function- Zlib (mutually exclusive)
Example
Create the recommended number of shards and loop over their guild events in parallel
use ;
use signal;
use ;
use Client;
static SHUTDOWN: AtomicBool = new;
async
async
There are a few additional examples located in the repository.