Example #1
0
func TestPushChanneler(t *testing.T) {
	endpoint := "tcp://127.0.0.1:9999"

	pull, err := goczmq.NewPull(endpoint)
	if err != nil {
		t.Error(err)
	}
	defer pull.Destroy()

	push, err := NewPushChanneler(endpoint)
	defer push.Destroy()
	if err != nil {
		t.Fatal(err)
	}

	push.SendChan <- [][]byte{[]byte("Hello")}

	msg, more, err := pull.RecvFrame()

	if err != nil {
		t.Fatal(err)
	}

	text := string(msg)

	if text != "Hello" {
		t.Fatal("Wrong message")
	}

	if more != 0 {
		t.Fatal("More flag is wrong")
	}
}
Example #2
0
func main() {
	var messageSize = flag.Int("message_size", 0, "size of message")
	var messageCount = flag.Int("message_count", 0, "number of messages")
	flag.Parse()

	pullSock, err := czmq.NewPull("inproc://test")
	if err != nil {
		panic(err)
	}

	defer pullSock.Destroy()

	go func() {
		pushSock, err := czmq.NewPush("inproc://test")
		if err != nil {
			panic(err)
		}

		defer pushSock.Destroy()
		for i := 0; i < *messageCount; i++ {
			payload := make([]byte, *messageSize)
			err = pushSock.SendMessage([][]byte{payload})
			if err != nil {
				panic(err)
			}
		}
	}()

	startTime := time.Now()
	for i := 0; i < *messageCount; i++ {
		msg, err := pullSock.RecvMessage()
		if err != nil {
			panic(err)
		}
		if len(msg) != 1 {
			panic("msg too small")
		}
	}
	endTime := time.Now()
	elapsed := endTime.Sub(startTime)
	throughput := float64(*messageCount) / elapsed.Seconds()
	megabits := float64(throughput*float64(*messageSize)*8.0) / 1e6

	log.Printf("message size: %d", *messageSize)
	log.Printf("message count: %d", *messageCount)
	log.Printf("test time (seconds): %f", elapsed.Seconds())
	log.Printf("mean throughput: %f [msg/s]", throughput)
	log.Printf("mean throughput: %f [Mb/s]", megabits)
}
Example #3
0
func TestPushChanneler(t *testing.T) {
	endpoint := "tcp://127.0.0.1:9999"

	pull, err := goczmq.NewPull(endpoint)
	if err != nil {
		t.Error(err)
	}
	defer pull.Destroy()

	push, err := NewPushChanneler(endpoint)
	defer push.Destroy()
	if err != nil {
		t.Fatal(err)
	}
}
Example #4
0
func Setup() {
	config := config.Read()
	broadcastUri := fmt.Sprintf("tcp://%s:%d", config.Broadcaster.Host, config.Broadcaster.Port)

	var err error
	broadcaster, err = goczmq.NewPub(broadcastUri)
	if err != nil {
		panic(err)
	}
	log.Println("Broadcaster will start on", broadcastUri)

	pitcher = goczmq.NewSock(goczmq.Push)

	receiver, err = goczmq.NewPull("inproc://broadcast")
	if err != nil {
		panic(err)
	}

	helpers.ConnectToPeers(true, ConnectToBroadcatcher)
}