mirror of
https://github.com/mochi-mqtt/server.git
synced 2025-09-27 04:26:23 +08:00

* invalid config type provided examples/persistence/bolt/main.go: invalid config type provided * fixed ErrReceiveMaximum(receive maximum exceeded) No quotas of the inflight is set in the readStore method, so each quota is equal to 0. The inheritClientSession method overrides the quotas of the new client inflight, so the processPublish method reports an ErrReceiveMaximum and disconnects the client. * reset receive quota receive quota should be reset across connections (as specified in the spec).
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
// SPDX-License-Identifier: MIT
|
|
// SPDX-FileCopyrightText: 2022 mochi-co
|
|
// SPDX-FileContributor: mochi-co
|
|
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/mochi-co/mqtt/v2"
|
|
"github.com/mochi-co/mqtt/v2/hooks/auth"
|
|
"github.com/mochi-co/mqtt/v2/hooks/storage/bolt"
|
|
"github.com/mochi-co/mqtt/v2/listeners"
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
func main() {
|
|
sigs := make(chan os.Signal, 1)
|
|
done := make(chan bool, 1)
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
go func() {
|
|
<-sigs
|
|
done <- true
|
|
}()
|
|
|
|
server := mqtt.New(nil)
|
|
_ = server.AddHook(new(auth.AllowHook), nil)
|
|
|
|
err := server.AddHook(new(bolt.Hook), &bolt.Options{
|
|
Path: "bolt.db",
|
|
Options: &bbolt.Options{
|
|
Timeout: 500 * time.Millisecond,
|
|
},
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
tcp := listeners.NewTCP("t1", ":1883", nil)
|
|
err = server.AddListener(tcp)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
go func() {
|
|
err := server.Serve()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}()
|
|
|
|
<-done
|
|
server.Log.Warn().Msg("caught signal, stopping...")
|
|
server.Close()
|
|
server.Log.Info().Msg("main.go finished")
|
|
}
|