mirror of
				https://github.com/mochi-mqtt/server.git
				synced 2025-10-31 03:26:28 +08:00 
			
		
		
		
	 26418c6fd8
			
		
	
	26418c6fd8
	
	
	
		
			
			* Implement file-based configuration * Implement file-based configuration * Replace DefaultServerCapabilities with NewDefaultServerCapabilities() to avoid data race (#360) Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com> * Only pass a copy of system.Info to hooks (#365) * Only pass a copy of system.Info to hooks * Rename Itoa to Int64toa --------- Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com> * Allow configurable max stored qos > 0 messages (#359) * Allow configurable max stored qos > 0 messages * Only rollback Inflight if QoS > 0 * Only rollback Inflight if QoS > 0 * Minor refactor * Update server version * Implement file-based configuration * Implement file-based configuration * update configs with maximum_inflight value * update docker configuration * fix tests --------- Co-authored-by: mochi-co <moumochi@icloud.com> Co-authored-by: thedevop <60499013+thedevop@users.noreply.github.com>
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // SPDX-License-Identifier: MIT
 | |
| // SPDX-FileCopyrightText: 2022 mochi-mqtt, mochi-co
 | |
| // SPDX-FileContributor: mochi-co
 | |
| 
 | |
| package main
 | |
| 
 | |
| import (
 | |
| 	"flag"
 | |
| 	"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/listeners"
 | |
| )
 | |
| 
 | |
| func main() {
 | |
| 	tcpAddr := flag.String("tcp", ":1883", "network address for TCP listener")
 | |
| 	flag.Parse()
 | |
| 
 | |
| 	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.Options.Capabilities.MaximumClientWritesPending = 16 * 1024
 | |
| 	_ = server.AddHook(new(auth.AllowHook), nil)
 | |
| 
 | |
| 	tcp := listeners.NewTCP(listeners.Config{
 | |
| 		ID:      "t1",
 | |
| 		Address: *tcpAddr,
 | |
| 	})
 | |
| 	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")
 | |
| }
 |