-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a persistence hook based on cockroachdb/pebble. (#378)
* Implementing Pebble as a persistence database hook. * Fixed failing test cases. * Add Pebble DB configuration for file-based configuration, optimize part of the code. * Resolve test failure issues and perform code optimization. * Optimized the test cases.
- Loading branch information
Showing
12 changed files
with
1,984 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2022 mochi-mqtt, mochi-co, werbenhu | ||
// SPDX-FileContributor: werbenhu | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
mqtt "github.com/mochi-mqtt/server/v2" | ||
"github.com/mochi-mqtt/server/v2/hooks/auth" | ||
"github.com/mochi-mqtt/server/v2/hooks/storage/pebble" | ||
"github.com/mochi-mqtt/server/v2/listeners" | ||
) | ||
|
||
func main() { | ||
pebblePath := ".pebble" | ||
defer os.RemoveAll(pebblePath) // remove the example pebble files at the end | ||
|
||
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(pebble.Hook), &pebble.Options{ | ||
Path: pebblePath, | ||
Mode: pebble.NoSync, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
tcp := listeners.NewTCP(listeners.Config{ | ||
ID: "t1", | ||
Address: ":1883", | ||
}) | ||
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("caught signal, stopping...") | ||
_ = server.Close() | ||
server.Log.Info("main.go finished") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.