Giter VIP home page Giter VIP logo

talos-sdk-golang's Introduction

Installing

Install your specific service package with the following command.

  1. GoPath

You can install the entire SDK to GoPath by go get:

$ go get github.com/XiaoMi/talos-sdk-golang

  1. Go modules

Or add the module to your go.mod:

go mod edit -require=github.com/XiaoMi/[email protected]

Tutorial

We have an Tutorial Demo in package example/, here we choose talos_consumer to explain the use process

import

To use SDK, import like this:

import (
	"github.com/XiaoMi/talos-sdk-golang/consumer"
	"github.com/XiaoMi/talos-sdk-golang/utils"
	log "github.com/sirupsen/logrus"
)

Configuration profile

Reference talosConsumer.conf, you can configure like this:

galaxy.talos.service.endpoint=ENDPOINT

galaxy.talos.topic.name=MY-TOPIC

galaxy.talos.access.key=MY-APP-KEY

galaxy.talos.access.secret=MY-SECRET-KEY

Notice

  • Before using the Talos SDK, ensure that you've correct credential and base information
  • Other configurations can remain the default

Coding

    // user can customize log format or use default format
    // log.SetOutput(os.Stdout)
    // log.SetLevel(log.InfoLevel)
    utils.InitLog()
    
    // init properties from talosConsumer.conf
    var propertyFilename string
    flag.StringVar(&propertyFilename, "conf", "talosProducer.conf", "conf: talosConsumer.conf'")
    flag.Parse()
    
    // constructor
    talosConsumer, err := consumer.NewTalosConsumerByFilename(propertyFilename, 
        NewMyMessageProcessorFactory(),
        client.NewSimpleTopicAbnormalCallback())
    if err != nil {
        log.Errorf("init talosConsumer failed: %s", err.Error())
        return
    }
    
    // shutdown, graceful exit
    go func() {
        time.Sleep(5 * time.Second)
        talosConsumer.ShutDown()
    }()
    
    // block main function and wait shutdown
    talosConsumer.WaitGroup.Wait()

Go run & Go build

Then user can run this demo to fetch data

$ go run $path/TalosConsumerDemo.go [-config] [$path/talosConsumer.conf]

or

$ cd example/talos_consumer
$ go build TalosConsumerDemo.go
$ ./TalosConsumerDemo [-config] [$path/talosConsumer.conf]

Talos Book

Talos Wiki

talos-sdk-golang's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.