From 10c27e60ee5d2a2fa3b2602cb0b61ac94c846c43 Mon Sep 17 00:00:00 2001 From: David Thorpe Date: Sun, 3 Oct 2021 17:21:26 +0200 Subject: [PATCH] Updated mosquitto to mutablelogic org --- Makefile | 2 +- README.md | 113 +++--------------------------- cmd/mqttpub/main.go | 4 +- cmd/mqttsub/main.go | 4 +- etc/nfpm/go-server-mqtt/nfpm.yaml | 2 +- go.mod | 2 +- pkg/app/app.go | 2 +- pkg/config/version.go | 2 +- pkg/mosquitto/event.go | 2 +- pkg/mosquitto/mosquitto.go | 4 +- pkg/mosquitto/mosquitto_test.go | 2 +- plugin/mqtt/main.go | 4 +- plugin/mqtt/schema.go | 2 +- sys/mosquitto/doc.go | 2 +- sys/mosquitto/mosquitto_test.go | 22 +++--- 15 files changed, 38 insertions(+), 131 deletions(-) diff --git a/Makefile b/Makefile index 7498480..22a736b 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ CMD_DIR := $(filter-out cmd/README.md, $(wildcard cmd/*)) PLUGIN_DIR := $(wildcard plugin/*) # Build flags -BUILD_MODULE = "github.com/djthorpe/go-mosquitto" +BUILD_MODULE = "github.com/mutablelogic/go-mosquitto" BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/config.GitSource=${BUILD_MODULE} BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/config.GitTag=$(shell git describe --tags) BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/config.GitBranch=$(shell git name-rev HEAD --name-only --always) diff --git a/README.md b/README.md index 41d7831..0c46012 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,19 @@ This repository contains a Golang [mosquitto](https://mosquitto.org/) client library, which conforms to the MQTT standard. This documentation includes the following information: - * What dependencies are needed in order to use this package - * Information about the two command-line tools, `mqttpub` and `mqttsub` - * Using the `libmosquitto` bindings - * Alternatively, using the `gopi.Unit` interface - -This repository is published under the Apache license. Please use the [issues](https://github.com/djthorpe/mosquitto/issues) tab on Github to file bugs, ask for features or + * What dependencies are needed in order to use this package; + * Information about the two command-line tools, `mqttpub` and `mqttsub`; + * Using the `libmosquitto` bindings; + * Alternatively, using the higher-level package; + * Building a REST API frontend to mqtt. + +This repository is published under the Apache license. +Please use the [issues](https://github.com/mutablelogic/mosquitto/issues) tab on Github to file bugs, ask for features or for general discussion. ## Copyright Notice -> Copyright 2020 David Thorpe +> Copyright 2020, 2021 David Thorpe > > Licensed under the Apache License, Version 2.0 (the "License"); > you may not use this file except in compliance with the License. @@ -83,7 +85,7 @@ You can use the following `libmosquitto` bindings in your code. For informaton about the C API, please see [here](https://mosquitto.org/api/files/mosquitto-h.html): ```go -package mosquitto // import "github.com/djthorpe/mosquitto/sys/mosquitto" +package mosquitto const MOSQ_DEFAULT_PORT = 1883 @@ -169,98 +171,3 @@ func (this *Message) Len() uint func (this *Message) Qos() int func (this *Message) Retain() bool ``` - -## Using the gopi.Unit - -Alternatively, the gopi.Unit interface provides an easy way to use the MQTT -client. The interface is as follows: - -```go -type Client interface { - // Connect to MQTT broker with options - Connect(...Opt) error - - // Disconnect from MQTT broker - Disconnect() error - - // Subscribe to topic with wildcard and return request-id - Subscribe(string, ...Opt) (int, error) - - // Unsubscribe from topic with wildcard and return request-id - Unsubscribe(string) (int, error) - - // Publish []byte data to topic and return request-id - Publish(string, []byte, ...Opt) (int, error) - - // Publish JSON data to topic and return request-id - PublishJSON(string, interface{}, ...Opt) (int, error) - - // Publish measurements in influxdata line protocol format and return request-id - PublishInflux(string, string, map[string]interface{}, ...Opt) (int, error) - - // Wait for a specific request-id or 0 for a connect or disconnect event - // with context (for timeout) - WaitFor(context.Context, int) (Event, error) - - // Implements gopi.Unit - gopi.Unit -} -``` - -Publishing can be done for objects using `PublishJSON` and in InfluxDB line protocol format for measurements. You need to use the `WaitFor` function to wait for acknowledgement of operatons. For example, the following function connects -to a broker, waits for the connection to be acknowledged, publishes measurements -and then disconnects from the broker: - -```go -func Publish(app gopi.App,values map[string]interface{},opts []mqtt.Opts) error { - client := app.UnitInstance("mosquitto").(mqtt.Client) - if err := client.Connect(); err != nil { - return err - } else if _,err := client.WaitFor(context.Background(),0); err != nil { - return err - } else if id,err := client.PublishInflux("topic","measurement",values,opts...); err != nil { - return err - } else if _,err := client.WaitFor(context.Background(),id); err != nil { - return err - } else if err := client.Disconnect(); err != nil { - return err - } else if _,err := client.WaitFor(context.Background(),0); err != nil { - return err - } else { - return nil - } -} -``` - -The unit emits objects of type `mosquitto.Event` on the message bus: - -```go -type Event interface { - Type() Flags - Id() int - ReturnCode() int // For CONNECT and DISCONNECT - Topic() string - Data() []byte - - // Implements gopi.Event - gopi.Event -} -``` - -The types of events are as follows: - -```go -const ( - MOSQ_FLAG_EVENT_CONNECT - MOSQ_FLAG_EVENT_DISCONNECT - MOSQ_FLAG_EVENT_SUBSCRIBE - MOSQ_FLAG_EVENT_UNSUBSCRIBE - MOSQ_FLAG_EVENT_PUBLISH - MOSQ_FLAG_EVENT_MESSAGE - MOSQ_FLAG_EVENT_LOG -) -``` - -Please see the sample code under the `cmd` folder in the repository for -examples on using the code. - diff --git a/cmd/mqttpub/main.go b/cmd/mqttpub/main.go index 694069c..f8aa221 100644 --- a/cmd/mqttpub/main.go +++ b/cmd/mqttpub/main.go @@ -13,8 +13,8 @@ import ( "time" // Packages - "github.com/djthorpe/go-mosquitto/pkg/app" - "github.com/djthorpe/go-mosquitto/pkg/config" + "github.com/mutablelogic/go-mosquitto/pkg/app" + "github.com/mutablelogic/go-mosquitto/pkg/config" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/cmd/mqttsub/main.go b/cmd/mqttsub/main.go index 3324030..17fbca8 100644 --- a/cmd/mqttsub/main.go +++ b/cmd/mqttsub/main.go @@ -11,8 +11,8 @@ import ( "time" // Packages - "github.com/djthorpe/go-mosquitto/pkg/app" - "github.com/djthorpe/go-mosquitto/pkg/config" + "github.com/mutablelogic/go-mosquitto/pkg/app" + "github.com/mutablelogic/go-mosquitto/pkg/config" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/etc/nfpm/go-server-mqtt/nfpm.yaml b/etc/nfpm/go-server-mqtt/nfpm.yaml index 4eab749..d592517 100644 --- a/etc/nfpm/go-server-mqtt/nfpm.yaml +++ b/etc/nfpm/go-server-mqtt/nfpm.yaml @@ -7,7 +7,7 @@ maintainer: "David Thorpe " description: | Plugggable go-server monolith: mqtt vendor: "mutablelogic.com" -homepage: "https://github.com/djthorpe/go-mosquitto" +homepage: "https://github.com/mutablelogic/go-mosquitto" depends: - go-server-httpserver - go-server-sqlite3 diff --git a/go.mod b/go.mod index 7477a13..03733cb 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/djthorpe/go-mosquitto +module github.com/mutablelogic/go-mosquitto go 1.13 diff --git a/pkg/app/app.go b/pkg/app/app.go index 46c94c0..d9afad1 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -5,7 +5,7 @@ import ( "fmt" // Packages - "github.com/djthorpe/go-mosquitto/pkg/mosquitto" + "github.com/mutablelogic/go-mosquitto/pkg/mosquitto" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/pkg/config/version.go b/pkg/config/version.go index 6dbcc43..9344001 100644 --- a/pkg/config/version.go +++ b/pkg/config/version.go @@ -6,7 +6,7 @@ import ( "runtime" // Packages - mosq "github.com/djthorpe/go-mosquitto/sys/mosquitto" + mosq "github.com/mutablelogic/go-mosquitto/sys/mosquitto" ) /////////////////////////////////////////////////////////////////////////////// diff --git a/pkg/mosquitto/event.go b/pkg/mosquitto/event.go index 9249da7..180e5dc 100644 --- a/pkg/mosquitto/event.go +++ b/pkg/mosquitto/event.go @@ -4,7 +4,7 @@ import ( "fmt" // Namespace imports - . "github.com/djthorpe/go-mosquitto" + . "github.com/mutablelogic/go-mosquitto" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/pkg/mosquitto/mosquitto.go b/pkg/mosquitto/mosquitto.go index 6574116..2bea8f7 100644 --- a/pkg/mosquitto/mosquitto.go +++ b/pkg/mosquitto/mosquitto.go @@ -9,12 +9,12 @@ import ( "time" // Packages - mosq "github.com/djthorpe/go-mosquitto/sys/mosquitto" + mosq "github.com/mutablelogic/go-mosquitto/sys/mosquitto" multierror "github.com/hashicorp/go-multierror" // Namespace imports . "github.com/djthorpe/go-errors" - . "github.com/djthorpe/go-mosquitto" + . "github.com/mutablelogic/go-mosquitto" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/pkg/mosquitto/mosquitto_test.go b/pkg/mosquitto/mosquitto_test.go index 40e789a..7430984 100644 --- a/pkg/mosquitto/mosquitto_test.go +++ b/pkg/mosquitto/mosquitto_test.go @@ -6,7 +6,7 @@ import ( "time" // Namespace imports - . "github.com/djthorpe/go-mosquitto/pkg/mosquitto" + . "github.com/mutablelogic/go-mosquitto/pkg/mosquitto" ) const ( diff --git a/plugin/mqtt/main.go b/plugin/mqtt/main.go index 89cfd41..60ace60 100644 --- a/plugin/mqtt/main.go +++ b/plugin/mqtt/main.go @@ -6,12 +6,12 @@ import ( "time" // Packages - "github.com/djthorpe/go-mosquitto/pkg/mosquitto" + "github.com/mutablelogic/go-mosquitto/pkg/mosquitto" "github.com/hashicorp/go-multierror" // Namespace imports . "github.com/djthorpe/go-errors" - . "github.com/djthorpe/go-mosquitto" + . "github.com/mutablelogic/go-mosquitto" . "github.com/mutablelogic/go-server" . "github.com/mutablelogic/go-sqlite" diff --git a/plugin/mqtt/schema.go b/plugin/mqtt/schema.go index d0a7ee9..249c6e8 100644 --- a/plugin/mqtt/schema.go +++ b/plugin/mqtt/schema.go @@ -11,7 +11,7 @@ import ( "unicode/utf8" // Package imports - "github.com/djthorpe/go-mosquitto/pkg/mosquitto" + "github.com/mutablelogic/go-mosquitto/pkg/mosquitto" // Namespace imports . "github.com/djthorpe/go-errors" diff --git a/sys/mosquitto/doc.go b/sys/mosquitto/doc.go index 8f59cc6..b716af5 100644 --- a/sys/mosquitto/doc.go +++ b/sys/mosquitto/doc.go @@ -2,6 +2,6 @@ MQTT client bindings for the Go programming language which bind to https://mosquitto.org/api/files/mosquitto-h.html For more information please see - https://github.com/djthorpe/go-mosquitto/blob/master/README.md + https://github.com/mutablelogic/go-mosquitto/blob/master/README.md */ package mosquitto diff --git a/sys/mosquitto/mosquitto_test.go b/sys/mosquitto/mosquitto_test.go index 85b3902..045ea9c 100644 --- a/sys/mosquitto/mosquitto_test.go +++ b/sys/mosquitto/mosquitto_test.go @@ -6,8 +6,8 @@ import ( "time" // Namespace imports - "github.com/djthorpe/go-mosquitto/sys/mosquitto" - . "github.com/djthorpe/go-mosquitto/sys/mosquitto" + + . "github.com/mutablelogic/go-mosquitto/sys/mosquitto" ) const ( @@ -58,12 +58,12 @@ func Test_Mosquitto_003(t *testing.T) { } func Test_Mosquitto_004(t *testing.T) { - if err := mosquitto.Init(); err != nil { + if err := Init(); err != nil { t.Fatal(err) } - defer mosquitto.Cleanup() + defer Cleanup() - client, err := mosquitto.NewEx("id", true) + client, err := NewEx("id", true) if err != nil { t.Error(err) } @@ -117,12 +117,12 @@ func Test_Mosquitto_005(t *testing.T) { } func Test_Mosquitto_006(t *testing.T) { - if err := mosquitto.Init(); err != nil { + if err := Init(); err != nil { t.Fatal(err) } - defer mosquitto.Cleanup() + defer Cleanup() - client, err := mosquitto.NewEx("id", true) + client, err := NewEx("id", true) if err != nil { t.Error(err) } @@ -170,12 +170,12 @@ func Test_Mosquitto_006(t *testing.T) { } func Test_Mosquitto_007(t *testing.T) { - if err := mosquitto.Init(); err != nil { + if err := Init(); err != nil { t.Fatal(err) } - defer mosquitto.Cleanup() + defer Cleanup() - client, err := mosquitto.NewEx("id", true) + client, err := NewEx("id", true) if err != nil { t.Error(err) }