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).
- Support pub/sub mechanism based on CoAP
- It include a simple client/server
- Add extra heart beat mechanism to ensure UDP tunnel alive.
go get github.com/kkdai/coapmq
- Install simple server:
go get github.com/kkdai/coapmq/coapmq_server
- Install simple interactive client:
go get github.com/kkdai/coapmq/coapmq_client
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")
}
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)
}
#####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
TBD
- 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
It is one of my project 52.
This package is licensed under MIT license. See LICENSE for details.