Home

Awesome

CoAPMQ: Publish-Subscribe Broker for the Constrained Application Protocol (CoAP) in Golang

GitHub license GoDoc Build Status

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

Install

Install package:

Install binary:

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:


//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

Project52

It is one of my project 52.

License

This package is licensed under MIT license. See LICENSE for details.