Nats integration improvements, unified TLSConfig for Nats and GRPC client #840
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.