コード例 #1
0
ファイル: main.go プロジェクト: rgbkrk/juno
func main() {
	var connFile = flag.String("connection-file", "", "Path to connection file")
	flag.Parse()

	if *connFile == "" {
		fmt.Fprint(os.Stderr, "Connection file is required\n")
		flag.Usage()
		os.Exit(2)
	}

	connInfo, err := juno.NewConnectionInfo(*connFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to open connection file\n")
		fmt.Fprintln(os.Stderr, err)
		os.Exit(3)
	}

	ioConnection := connInfo.IOPubConnectionString()
	iopub := zmq.NewSubChanneler(ioConnection, "")

	defer iopub.Destroy()

	broker := ssebroker.NewServer()

	go func() {
		for {
			select {
			case wireMessage := <-iopub.RecvChan:
				var message juno.Message
				err := message.ParseWireProtocol(wireMessage, connInfo)
				if err != nil {
					fmt.Fprintf(os.Stderr, "Unable to read message %v\n", err)
				}

				b, err := json.Marshal(message)

				broker.Notifier <- b
			}
		}
	}()

	log.Fatal("HTTP server error: ", http.ListenAndServe("localhost:3000", broker))

}
コード例 #2
0
ファイル: main.go プロジェクト: rgbkrk/juno
func main() {
	var connFile = flag.String("connection-file", "", "Path to connection file")
	flag.Parse()

	if *connFile == "" {
		fmt.Fprint(os.Stderr, "Connection file is required\n")
		flag.Usage()
		os.Exit(2)
	}

	connInfo, err := juno.NewConnectionInfo(*connFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to open connection file\n")
		fmt.Fprintln(os.Stderr, err)
		os.Exit(3)
	}

	ioConnection := connInfo.IOPubConnectionString()
	iopub := zmq.NewSubChanneler(ioConnection, "")

	defer iopub.Destroy()

	// Listen for messages... forever!
	for {
		select {
		case wireMessage := <-iopub.RecvChan:
			var message juno.Message
			err := message.ParseWireProtocol(wireMessage, connInfo)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Unable to read message %v\n", err)
			}
			fmt.Println(message)
		}
	}

}
コード例 #3
0
ファイル: iolo.go プロジェクト: rgbkrk/iolopub
func main() {
	connFile := flag.String("existing", "", "Path to connection file")
	ioloHub := flag.String("hub", "http://iolo.fict.io:80", "IOLO Hub Base URL")
	flag.Parse()

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		flag.PrintDefaults()
		fmt.Println()
	}

	if *connFile == "" {
		flag.Usage()
		log.Fatalln("Need a connection file.")
	}

	// Expects a runtime kernel-*.json
	connInfo, err := juno.NewConnectionInfo(*connFile)

	if err != nil {
		log.Fatalf("%v\n", err)
	}

	u, err := url.Parse(*ioloHub)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to parse URL: %v", err)
		os.Exit(3)
	}

	u.Path = "/ws"

	rawConn, err := net.Dial("tcp", u.Host)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to connect to host: %v", err)
		os.Exit(4)
	}

	wsHeaders := http.Header{
		"Origin":                   {u.Scheme + "://" + u.Host},
		"Sec-WebSocket-Extensions": {"permessage-deflate; client_max_window_bits, x-webkit-deflate-frame"},
	}

	writeBufferSize := 1024 * 1024 * 2

	wsConn, resp, err := websocket.NewClient(rawConn, u, wsHeaders, 0, writeBufferSize)
	if err != nil {
		fmt.Fprintf(os.Stderr, "websocket.NewClient Error: %s\nResp:%+v", err, resp)
		os.Exit(5)
	}
	defer wsConn.Close()

	ioConnection := connInfo.IOPubConnectionString()
	iopub := zmq.NewSubChanneler(ioConnection, "")
	defer iopub.Destroy()

	for {
		select {
		case wireMessage := <-iopub.RecvChan:
			var message juno.Message
			err := message.ParseWireProtocol(wireMessage, connInfo)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Unable to read message %v\n", err)
				continue
			}
			err = wsConn.WriteJSON(message)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Problem writing JSON %v.\nOutput too big?", err)
				break
			}
		}
	}

}
コード例 #4
0
ファイル: client.go プロジェクト: rgbkrk/juno
func main() {
	var connFile = flag.String("connection-file", "", "Path to connection file")
	var lampostServer = flag.String("lampost-server", "https://lampost.lambdaops.com", "URL to a lampost server")
	flag.Parse()

	if *connFile == "" {
		fmt.Fprint(os.Stderr, "Connection file is required\n")
		flag.Usage()
		os.Exit(2)
	}

	connInfo, err := juno.NewConnectionInfo(*connFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to open connection file\n")
		fmt.Fprintln(os.Stderr, err)
		os.Exit(3)
	}

	ioConnection := connInfo.IOPubConnectionString()
	iopub := zmq.NewSubChanneler(ioConnection, "")

	defer iopub.Destroy()

	var wg sync.WaitGroup
	wg.Add(1)

	go func() {
		defer wg.Done()
		for {
			select {
			case wireMessage := <-iopub.RecvChan:
				var message juno.Message
				err := message.ParseWireProtocol(wireMessage, connInfo)

				if err != nil {
					fmt.Fprintf(os.Stderr, "Unable to read message %v\n", err)
				}

				b, err := json.Marshal(message)
				reader := bytes.NewReader(b)

				resp, err := http.Post(*lampostServer+"/api/ioju", "application/json", reader)
				if err != nil {
					fmt.Fprintf(os.Stderr, "Unable to POST to %v with %v\n", *lampostServer, message)
					fmt.Fprintln(os.Stderr, err)
					if resp != nil {
						fmt.Fprintf(os.Stderr, "[%v] %v\n", resp.StatusCode, resp.Status)
					}
					return
				}

				if resp.StatusCode != 200 {
					fmt.Printf("[%v] %v\n", resp.StatusCode, resp.Status)
				}

			}
		}
		// This code is unreachable, but you would normally
		//     defer wg.Done()
		// once the goroutine was finished
	}()

	wg.Wait()

}