GithubHelp home page GithubHelp logo

emuxevans / coapmq Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kkdai/coapmq

0.0 2.0 0.0 21 KB

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

Go 100.00%

coapmq's Introduction

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

  • 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

Project52

It is one of my project 52.

License

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

coapmq's People

Contributors

kkdai avatar

Watchers

James Cloos avatar Emux Evans avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.