Skip to content

A friendly library to implement MQTT services. In go.

License

Notifications You must be signed in to change notification settings

annikahannig/alpaca-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alpaca

An opinionated library for writing services on a MQTT message bus.

IMPORTANT: I deceided to move this into an org: CamelIoT

Why?

Something along the lines of: After implementing DaliQTT I wanted something more generalized to create new services more easily.

I guess this will later need a python port aswell.

How to use

Creating a new service in your network is now as easy as:

dispatch, actions := alpaca.DialMqtt(
    "tcp://user:pass@localhost:1889",
    alpaca.Routes{
        "lights": "v1/upstairs/lights",
        "meta": "v1/_meta/",
    })

handle(actions, dispatch)

With a service handler like:

const GET_LIGHT_VALUE_REQUEST = "@lights/GET_LIGHT_VALUE_REQUEST"

type Light struct {
    Id     int `json:"id"`
    Value  int `json:"value"`
}

func handle(actions alpaca.Actions, dispatch alpaca.Dispatch) {
    // Do some more setup stuff...

    // Handle incoming actions
    for action := range actions {
        switch action.Type {
        case SET_LIGHT_VALUE_REQUEST:
            var light Light
            action.DecodePayload(&light)
            setLightValue(light.Id, light.Value) 
            dispatch(SetLightValueSuccess(light))
        }
    }
}

For a simple working example please checkout the examples/simple/simple.go string reversal service.

About

A friendly library to implement MQTT services. In go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages