Created
November 26, 2017 15:23
-
-
Save Roemerb/b7bfc7bff41e7ae0dc7fad0eb0165d60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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