Go Client Support for Streamdal

We're updating our documentation, so the presented info might not be the most recent.


If you’re developing with Go and aim to elevate your data operations, you’re in the right place. With Streamdal’s Go SDK, integrating the power of Streamdal into your Go applications has never been simpler.

Information

For detailed information on the Go SDK and its functionalities, refer to the Go SDK README.

Instrumentation

Start with the instrumentation guide if you haven’t already. It will walk you through the process of setting up Streamdal and its components.

Dive Into an Example

Wondering how it works in action? Here’s a simple Go code demonstrating the Streamdal integration:

package main

import (
	"context"
	"fmt"

	"github.com/streamdal/go-sdk"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	sc, _ := streamdal.New(&streamdal.Config{
		// Address of the streamdal server
		ServerURL: "streamdal-server.svc.cluster.local:8082",

		// Token used for authenticating with the streamdal server
		ServerToken: "1234",

		// Identify _this_ application/service (
		ServiceName: "billing-svc",

		// Used for shutting down processing and goroutines
		// Your application should call `cancel()` when it's time to shut down
		ShutdownCtx: ctx,
	})

	resp := sc.Process(ctx, &streamdal.ProcessRequest{
		OperationType: streamdal.OperationTypeConsumer,
		OperationName: "new-order-topic",
		ComponentName: "kafka",
		Data:          []byte(`{"object": {"field": true}}`),
	})

	// Check if the .Process() call completed
	if resp.Status != streamdal.ExecStatusError {
		fmt.Println("Successfully processed payload")
	}

	// Or you can inspect each individual pipeline & step result
	for _, pipeline := range resp.PipelineStatus {
		fmt.Printf("Inspecting '%d' steps in pipeline '%s'...\n", len(resp.PipelineStatus), pipeline.Name)

		for _, step := range pipeline.StepStatus {
			fmt.Printf("Step '%s' status: '%s'\n", step.Name, step.Status)
		}
	}
}

Example Code Breakdown

  • Imports:

    • Essential Go packages are imported to support the application’s functionality.
  • Context Creation:

    • A new context is established, ensuring timeouts and graceful shutdowns.
  • Streamdal Client Setup:

    • Here, the SDK client is initialized with various configurations, including the server URL, service name, and specific timeout intervals.
  • Error Handling:

    • Any initialization errors are caught. Should one occur, the program will immediately halt and display the error message.
  • Data Processing:

    • The Process() method of the Streamdal client is invoked. This processes the data while specifying details such as the operation type and the actual data to be processed.
  • Output:

    • The response from the processed data is then printed to the console, providing insight into the operation’s result.

Libraries

Here are the current list of Go libraries/wrappers/shims: