Various other refactoring

This commit is contained in:
Neil Alexander 2021-07-14 14:06:14 +01:00
parent 8f40e8fd5e
commit 48322bc2b2
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
12 changed files with 25 additions and 16 deletions

View file

@ -296,6 +296,8 @@ func (config *Dendrite) Derive() error {
func (c *Dendrite) Defaults() {
c.Version = 1
c.Wiring()
c.Global.Defaults()
c.ClientAPI.Defaults()
c.EDUServer.Defaults()
@ -309,8 +311,6 @@ func (c *Dendrite) Defaults() {
c.UserAPI.Defaults()
c.AppServiceAPI.Defaults()
c.MSCs.Defaults()
c.Wiring()
}
func (c *Dendrite) Verify(configErrs *ConfigErrors, isMonolith bool) {

View file

@ -5,21 +5,26 @@ import "fmt"
type JetStream struct {
Matrix *Global `yaml:"-"`
// Persistent directory to store JetStream streams in.
StoragePath Path `yaml:"storage_path"`
// A list of NATS addresses to connect to. If none are specified, an
// internal NATS server will be used when running in monolith mode only.
Addresses []string `yaml:"addresses"`
// The prefix to use for stream names for this homeserver - really only
// useful if running more than one Dendrite on the same NATS deployment.
TopicPrefix string `yaml:"topic_prefix"`
// Keep all storage in memory. This is mostly useful for unit tests.
InMemory bool `yaml:"-"`
}
func (k *JetStream) TopicFor(name string) string {
return fmt.Sprintf("%s%s", k.TopicPrefix, name)
func (c *JetStream) TopicFor(name string) string {
return fmt.Sprintf("%s%s", c.TopicPrefix, name)
}
func (c *JetStream) Defaults() {
c.Addresses = []string{}
c.TopicPrefix = "Dendrite"
c.StoragePath = Path(fmt.Sprintf("./%s", c.Matrix.ServerName))
}
func (c *JetStream) Verify(configErrs *ConfigErrors, isMonolith bool) {

View file

@ -27,7 +27,7 @@ func SetupConsumerProducer(cfg *config.JetStream) (sarama.Consumer, sarama.SyncP
ServerName: "monolith",
DontListen: true,
JetStream: true,
StoreDir: string(cfg.Matrix.ServerName),
StoreDir: string(cfg.Matrix.JetStream.StoragePath),
})
if err != nil {
panic(err)
@ -76,6 +76,12 @@ func setupNATS(cfg *config.JetStream, nc *natsclient.Conn) (sarama.Consumer, sar
stream.Name = cfg.TopicFor(stream.Name)
stream.Subjects = []string{stream.Name}
// If we're trying to keep everything in memory (e.g. unit tests)
// then overwrite the storage policy.
if cfg.InMemory {
stream.Storage = nats.MemoryStorage
}
if _, err = s.AddStream(stream); err != nil {
logrus.WithError(err).WithField("stream", stream.Name).Fatal("Unable to add stream")
}