How to enable JetStream for account in embedded nats? #6242
-
In an embedded nats I want to create a user This looks like a chicken and egg problem which I don't know how to solve using the available exported API. func nats() error {
appAcc := server.NewAccount("APP")
// NOTE: I can't enable jetstream because this account isn't yet registered with server
// if err := appAcc.EnableJetStream(nil); err != nil {
// return fmt.Errorf("failed to enable jet stream for APP account: %w", err)
// }
// var appAcc *server.Account
opts := &server.Options{
DontListen: true,
JetStream: true,
DisableJetStreamBanner: true,
Websocket: server.WebsocketOpts{
Host: "0.0.0.0",
Port: 55555,
NoTLS: true,
},
Accounts: []*server.Account{
appAcc,
},
Users: []*server.User{
{Username: "admin", Password: "admin", Account: appAcc},
},
}
ns, err := server.NewServer(opts)
if err != nil {
return fmt.Errorf("failed to initiate nats server: %w", err)
}
ns.ConfigureLogger()
go ns.Start()
if !ns.ReadyForConnections(time.Second * 5) {
return errors.New("nats server timeout while waiting to be ready")
}
prepare(ns)
<-ctx.Done()
ns.Shutdown()
ns.WaitForShutdown()
return nil
}
func prepare(ns *server.Server) {
nc, err := nats.Connect(nats.DefaultURL, nats.InProcessServer(ns), nats.UserInfo("admin", "admin"))
if err != nil {
panic(err)
}
js, err := nc.JetStream()
if err != nil {
panic(err)
}
kv, err := js.CreateKeyValue(&nats.KeyValueConfig{
Bucket: "projections",
Storage: nats.MemoryStorage,
})
if err != nil {
panic(err)
}
_ = kv
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Resolved in #6261 |
Beta Was this translation helpful? Give feedback.
Resolved in #6261