Skip to content

Instantly share code, notes, and snippets.

@Roemerb
Created November 26, 2017 15:23
Show Gist options
  • Save Roemerb/b7bfc7bff41e7ae0dc7fad0eb0165d60 to your computer and use it in GitHub Desktop.
Save Roemerb/b7bfc7bff41e7ae0dc7fad0eb0165d60 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"strconv"
"strings"
zmq "github.com/pebbe/zmq4"
)
func main() {
ctx, err := zmq.NewContext()
if err != nil {
panic(err)
}
subscriber, err := ctx.NewSocket(zmq.XSUB)
if err != nil {
panic(err)
fmt.Println(err.Error())
}
fmt.Println("Connecting...")
subscriber.Connect("tcp://pubsub.ndovloket.nl:7662")
subscriber.Send("\x01/", 0)
fmt.Println("Connected!")
for {
msg, err := subscriber.RecvMessage(0)
if err != nil {
panic(err)
}
fmt.Println("Message received consisting of: " + strconv.Itoa(len(msg)) + " parts")
//address := msg[0]
full := strings.Join(msg[1:], "")
rdata := bytes.NewReader([]byte(full))
gz, _ := gzip.NewReader(rdata)
s, _ := ioutil.ReadAll(gz)
fmt.Println(string(s))
}
defer subscriber.Close()
defer ctx.Term()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment