Skip to content

Instantly share code, notes, and snippets.

@jtacoma
Created May 12, 2013 17:19
Show Gist options
  • Save jtacoma/5564286 to your computer and use it in GitHub Desktop.
Save jtacoma/5564286 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"time"
zmq "github.com/alecthomas/gozmq"
)
func main() {
go func() {
var (
c *zmq.Context
s *zmq.Socket
err error
m [][]byte
)
if c, err = zmq.NewContext(); err != nil {
panic(err)
}
defer c.Close()
if s, err = c.NewSocket(zmq.SUB); err != nil {
panic(err)
}
defer s.Close()
if err = s.Connect("tcp://localhost:5561"); err != nil {
panic(err)
}
s.SetSubscribe("p")
count := 0
for {
m, err = s.RecvMultipart(0)
if err != nil {
panic(err)
} else {
log.Println("SUB:", count, string(m[0]))
count++
}
}
}()
var (
c *zmq.Context
s *zmq.Socket
err error
)
if c, err = zmq.NewContext(); err != nil {
panic(err)
}
defer c.Close()
if s, err = c.NewSocket(zmq.PUB); err != nil {
panic(err)
}
defer s.Close()
if err = s.Bind("tcp://*:5561"); err != nil {
panic(err)
}
for i := 0; i < 10000; i++ {
err = s.SendMultipart([][]byte{[]byte("ping")}, 0)
if err != nil {
panic(err)
}
}
time.Sleep(time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment