gobroke

package module
v0.0.0-...-297abb6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2022 License: BSD-2-Clause Imports: 24 Imported by: 0

README

gobroke

My own implementation of MQTT server. Advanced and free to use. Supports MQTT v3-5.

Installation

go get github.com/RoanBrand/gobroke

Basic Usage

import "github.com/RoanBrand/gobroke"

s := gobroke.Server{}
err := s.Run()
if err != nil {
	panic(err)
}
  • Run() starts a MQTT broker listening on TCP port 1883.
  • It blocks while service is running until Close() or Shutdown() is called.
  • Will return nil if successfully shut down, or provide an error otherwise.

Extended Configuration

s := gobroke.Server{}
s.TCP.Address = ""
s.TLS.Address = ":8883"
s.TLS.Cert = "certs/example.crt"
s.TLS.Key = "certs/example.key"
s.WS.Address = ":8080"

s.Run()
  • You can configure network protocols TCP, TLS, Websocket, and Secure Websocket (WSS).
  • Setting the Address field to "" disables the network protocol and listener.
  • If all addresses are blank, or no config is provided, the server will default to using just TCP ":1883"
  • See internal/config/config.go for all options.

OS Service (Standalone Build)

  • The service can be built into a standalone server binary executable by running make build

  • Copy the gobroke binary and config.json to server folder and run gobroke -service install

  • Service can then be started with gobroke -service start or from the OS Service Manager

  • The config file can be omitted, in which case the server will just listen on TCP ":1883"

  • Example JSON config file for standalone server:

{
	"tcp": {
		"address": ":1883"                 // ip/host & port
	},
	"tls": {                                   // Secure TCP
		"address": ":8883",
		"cert": "path_to_TLS_certificate",
		"key": "path_to_private_key"
	},
	"ws": {                                    // Websocket
		"address": ":80",
		"check_origin": false              // check request origin
	},
	"wss": {                                   // Secure Websocket over HTTPS
		"address": ":443",
		"check_origin": false,
		"cert": "path_to_TLS_certificate",
		"key": "path_to_private_key"
	},
	"log": {
		"file": "path_to_log_file",        // log to file if specified
		"level": "info"                    // error, warn, info, debug
	}
}
  • See config.json for an example config file.
  • Config file path can be overridden with gobroke -c="path_to_config_file"
TLS
  • Example self-signed certificates included that can be used by MQTT clients on localhost
  • Make sure MQTT client does not use regular TCP port (default 8883, not 1883)
Websocket
  • The address must contain host/ip only and no URL. Currently it is served over all URLs
  • check_origin ensures that Origin request header is present and that the origin host is equal to request Host header before accepting a connection
Authentication and Authorization
  • See gobroke/auth package

Test

  • make test

TODO

  • MQTT 5:

    • Better Shared Subscription client choosing algo
    • Remaining Reason Codes & Reason Strings
    • AUTH
  • $SYS Topic

  • Tests to cover entire MQTT spec

  • Persistence (levelDB?)

  • Rate limiting?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	config.Config
	auth.Auther
	// contains filtered or unexported fields
}

func (*Server) Close

func (s *Server) Close() error

func (*Server) Run

func (s *Server) Run() error

func (*Server) Shutdown

func (s *Server) Shutdown()

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL