This pull request contains changes to use Nats broker in raw mode. In this mode Centrifugo skips its own message wrapping and just consumes Nats topics as is. In this mode Centrifugo does not use any prefix for channels by default, though it's still possible to define one. Centrifugo still uses its own format for control messages when raw mode is used. To work with namespaces which use : as separator this pr provides a way to define channel replacements mapping for Nats channels. For example, this allows using ns:channel in app but transform it to ns.channel in Nats when subscribing to Nats topic, and then upon consuming from Nats topic publish to the original channel ns:channel.
There is a work to allow using multiple brokers and presence managers in Centrifugo on per-namespace level, it will be a Centrifugo PRO feature. This adds a great level of flexibility to use various channel properties provided by different brokers in different namespaces, new ways to scale – having separate Redis instances for separate namespaces, combining Redis and Nats.
Wildcard subscriptions with Nats
It's also now possible to use wildcard subscriptions with Nats. This must be explicitly turned on using a separate option. In that case though Centrifugo features like presence, join/leave events, history, recovery won't work. But still can be useful for a variety of use cases. Users must be very careful with permissions when using wildcard channels – this should be emphasised in the doc.
TLS for Nats, unified TLSConfig
Also, supporting TLS configuration for Nats here. It uses a new approach using a unified TLSConfig object (see #831 ).
TLS for proxy GRPC client
Also added support for TLS in GRPC client (to address #839 ) – also utilizing a new TLSConfig structure for that.
Misc
Added integration tests for Nats.
I had to fork kelseyhightower/envconfig package to fit the needs of Centrifugo. Configuration is now a bit messy in implementation, but for users it's exposed in a very friendly way - both config file and env vars are supported, and we still have useful warnings in logs about unknown options used in config file or environment.
Proposed changes
Nats raw mode
This pull request contains changes to use Nats broker in raw mode. In this mode Centrifugo skips its own message wrapping and just consumes Nats topics as is. In this mode Centrifugo does not use any prefix for channels by default, though it's still possible to define one. Centrifugo still uses its own format for control messages when raw mode is used. To work with namespaces which use
:
as separator this pr provides a way to define channel replacements mapping for Nats channels. For example, this allows usingns:channel
in app but transform it tons.channel
in Nats when subscribing to Nats topic, and then upon consuming from Nats topic publish to the original channelns:channel
.There is a work to allow using multiple brokers and presence managers in Centrifugo on per-namespace level, it will be a Centrifugo PRO feature. This adds a great level of flexibility to use various channel properties provided by different brokers in different namespaces, new ways to scale – having separate Redis instances for separate namespaces, combining Redis and Nats.
Wildcard subscriptions with Nats
It's also now possible to use wildcard subscriptions with Nats. This must be explicitly turned on using a separate option. In that case though Centrifugo features like presence, join/leave events, history, recovery won't work. But still can be useful for a variety of use cases. Users must be very careful with permissions when using wildcard channels – this should be emphasised in the doc.
TLS for Nats, unified TLSConfig
Also, supporting TLS configuration for Nats here. It uses a new approach using a unified TLSConfig object (see #831 ).
TLS for proxy GRPC client
Also added support for TLS in GRPC client (to address #839 ) – also utilizing a new TLSConfig structure for that.
Misc
Added integration tests for Nats.
I had to fork
kelseyhightower/envconfig
package to fit the needs of Centrifugo. Configuration is now a bit messy in implementation, but for users it's exposed in a very friendly way - both config file and env vars are supported, and we still have useful warnings in logs about unknown options used in config file or environment.