mirror of
https://git.mills.io/prologic/msgbus.git
synced 2024-06-28 09:41:43 +00:00
![James Mills](/assets/img/avatar_default.png)
* Fixed drop rate for subscriber listeners by adding buffering to channels (configurable) * Added optinoal pprof support * Added profile target for running profiled benchmarks
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/mmcloughlin/professor"
|
|
"github.com/prologic/msgbus"
|
|
)
|
|
|
|
func main() {
|
|
var (
|
|
version bool
|
|
debug bool
|
|
bind string
|
|
bufferLength int
|
|
maxQueueSize int
|
|
maxPayloadSize int
|
|
)
|
|
|
|
flag.BoolVar(&version, "v", false, "display version information")
|
|
flag.BoolVar(&debug, "d", false, "enable debug logging")
|
|
|
|
flag.StringVar(&bind, "bind", ":8000", "interface and port to bind to")
|
|
|
|
flag.IntVar(&bufferLength, "buffer-length", msgbus.DefaultBufferLength, "buffer length")
|
|
flag.IntVar(&maxQueueSize, "max-queue-size", msgbus.DefaultMaxQueueSize, "maximum queue size")
|
|
flag.IntVar(&maxPayloadSize, "max-payload-size", msgbus.DefaultMaxPayloadSize, "maximum payload size")
|
|
|
|
flag.Parse()
|
|
|
|
if debug {
|
|
log.SetLevel(log.DebugLevel)
|
|
} else {
|
|
log.SetLevel(log.InfoLevel)
|
|
}
|
|
|
|
if version {
|
|
fmt.Printf("msgbusd %s", msgbus.FullVersion())
|
|
os.Exit(0)
|
|
}
|
|
|
|
if debug {
|
|
go professor.Launch(":6060")
|
|
}
|
|
|
|
opts := msgbus.Options{
|
|
BufferLength: bufferLength,
|
|
MaxQueueSize: maxQueueSize,
|
|
MaxPayloadSize: maxPayloadSize,
|
|
WithMetrics: true,
|
|
}
|
|
mb := msgbus.New(&opts)
|
|
|
|
http.Handle("/", mb)
|
|
http.Handle("/metrics", mb.Metrics().Handler())
|
|
log.Infof("msgbusd %s listening on %s", msgbus.FullVersion(), bind)
|
|
log.Fatal(http.ListenAndServe(bind, nil))
|
|
}
|