Awesome
CoAPMQ: Publish-Subscribe Broker for the Constrained Application Protocol (CoAP) in Golang
Features
It is Golang implement based on draft RFC "Publish-Subscribe Broker for the Constrained Application Protocol (CoAP)". It is a replace version of CoAPMQ. This package based on latest draft spec (2016/01/22).
Features
- Support pub/sub mechanism based on CoAP
- It include a simple client/server
- Add extra heart beat mechanism to ensure UDP tunnel alive.
Install
Install package:
go get github.com/kkdai/coapmq
Install binary:
- Install simple server:
go get github.com/kkdai/coapmq/coapmq_server
- Install simple interactive client:
go get github.com/kkdai/coapmq/coapmq_client
Usage
Server side example
Create a 1024 buffer for pub/sub server and listen 5683 (default port for CoAP)
package main
import (
"log"
. "github.com/kkdai/coapmq"
)
func main() {
log.Println("Server start....")
serv := NewBroker(1024)
serv.ListenAndServe(":5683")
}
Client side example
Create a client to read input flag to send add/remove subscription to server.
package main
import (
"log"
. "github.com/kkdai/coapmq"
)
func main() {
serverAddr := "localhost:5683"
client := NewClient(serverAddr)
//Create Topic
err := client.CreateTopic("topic1")
err = client.CreateTopic("topic2")
//Remove Topic
err = RemoveTopic("topic2")
//Subsciption Topic
ch, err := client.Subscription("topic1")
log.Println("Wait and get sub:", <-ch)
}
Run interactive client with CoAPMQ
#####Parameters:
- "-s": Connect server address, default with "localhost:5683"
- "-v": Display log information.
//Check detail help file
>>coapmq_client --help
Client to connect to coapmq broker
Usage:
coapmq_client [flags]
Flags:
-s, --server="localhost:5683": coapmq server address
-v, --verbose[=false]: Verbose
//Run with local address
>>coapmq_client
Connect to coapmq server: localhost:5683
Command:( C:Create S:Subscription P:Publish R:RemoveTopic V:Verbose G:Read Q:exit )
//Create a topic "t1" on server
:>c t1
CreateTopic topic: t1 ret= <nil>
Command:( C:Create S:Subscription P:Publish R:RemoveTopic V:Verbose G:Read Q:exit )
//Subscribe topic "t1" on server
:>s t1
Subscription topic: t1 ret= <nil>
Command:( C:Create S:Subscription P:Publish R:RemoveTopic V:Verbose G:Read Q:exit )
//Publish data "test1" on topic "t1"
:>p t1 test1
Publish topic: t1 ret= <nil>
Command:( C:Create S:Subscription P:Publish R:RemoveTopic V:Verbose G:Read Q:exit )
:>
//Get call back Goroutine
>>> Got pub from topic: t1 pub: test1
Benchmark
TBD
Inspired
- CoAPMQ RFC Draft
- RFC 7252: The Constrained Application Protocol (CoAP)
- RFC 7641: Observing Resources in the Constrained Application Protocol (CoAP)
- MQTT and CoAP, IoT Protocols
- https://github.com/dustin/go-coap
- https://github.com/gotthardp/rabbitmq-coap-pubsub
Project52
It is one of my project 52.
License
This package is licensed under MIT license. See LICENSE for details.