Ejemplo n.º 1
0
Archivo: main.go Proyecto: nttlabs/cli
func main() {
	connection := consumer.NewDropsondeConsumer(DopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)

	messages, err := connection.RecentLogs(appGuid, authToken)

	if err != nil {
		fmt.Printf("===== Error getting recent messages: %v\n", err)
	} else {
		fmt.Println("===== Recent logs")
		for _, msg := range messages {
			fmt.Println(msg)
		}
	}

	fmt.Println("===== Streaming metrics")
	msgChan, err := connection.Stream(appGuid, authToken)

	if err != nil {
		fmt.Printf("===== Error streaming: %v\n", err)
	} else {
		for msg := range msgChan {
			fmt.Printf("%v \n", msg)
		}
	}
}
Ejemplo n.º 2
0
			testServer.Close()
		}
	})

	Describe("SetOnConnectCallback", func() {
		BeforeEach(func() {
			testServer = httptest.NewServer(handlers.NewWebsocketHandler(messagesToSend, 100*time.Millisecond))
			endpoint = "ws://" + testServer.Listener.Addr().String()
			close(messagesToSend)
		})

		It("sets a callback and calls it when connecting", func() {
			called := false
			cb := func() { called = true }

			connection = dropsonde_consumer.NewDropsondeConsumer(endpoint, tlsSettings, nil)
			connection.SetOnConnectCallback(cb)
			connection.TailingLogs(appGuid, authToken)

			Eventually(func() bool { return called }).Should(BeTrue())
		})

		Context("when the connection fails", func() {
			It("does not call the callback", func() {
				endpoint = "!!!bad-endpoint"

				called := false
				cb := func() { called = true }

				connection = dropsonde_consumer.NewDropsondeConsumer(endpoint, tlsSettings, nil)
				connection.SetOnConnectCallback(cb)