ravenworker

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

Raven-worker package

Description

Raven-worker is used as the base of every worker in the Raven framework.
A worker is a building block that can perform a specific task in a streaming data-flow.
A data-stream that is configured from one or multiple workers, is called a flow.
The goal of a flow is to filter, extract, enrich and store streaming data to easily manage all your (streaming) data.

Worker types

Workers come in three different types: extract, transform and load workers. These types are based on the graph theory where each worker represents a node.
Consider any Raven flow a directed acyclic graph.

How to use

The following functions are exposed by the package:

NewRavenworker

This initializes the worker.

For the Raven framework, a worker needs three variables to work with:

  • RavenURL to connect to the Raven framework.
  • WorkerID to identify itself and get new jobs.
  • FlowID to get the right jobs for the flow it belongs to and therefore receive the right events (messages) to process.

Example:

	c, _ := ravenworker.NewRavenworker(
		os.Getenv("RAVEN_URL"),
		os.Getenv("FLOW_ID"),
		os.Getenv("WORKER_ID"))

Now you can use the methods:

NewEvent

If the worker is of type extract (generates data or gets data from an external source), use the NewEvent method.
This method will generate new events for the flow.

Example:

	message := "Some message to send "
    err := c.NewEvent(message)
    if err != nil {
        fmt.Println(err)
    }
Consume

When a worker is of type transform or load, use Consume to retrieve the message from the stream.

Example:

    message, err := c.Consume()
    if err != nil {
        // handle err
    }
    // do something with the message
Produce

When a worker is of type transform or load, use Produce to put the new message or ack the message.
The actual content (payload) is stored in message.Content which takes a string.

Example:

		message.Content = "This is the new message: "
		err = c.Produce(message)
		if err != nil {
            // handle err
		}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	RavenURL string
	WorkerId string
	FlowId   string
}

func NewRavenworker

func NewRavenworker(ravenURL, flowId, workerId string) (*Config, error)

NewRavenworker returns a new configured raven worker client

func (Config) Consume

func (c Config) Consume() (Message, error)

Consume gets a message from the queue. A Message is returned when there is a job, sleeps with incremented interval when there are no messages and returns an error in case of one. Use this function for the 'transform' and 'load' worker types.

func (Config) NewEvent

func (c Config) NewEvent(msg string) error

NewEvent sends a ravenworker Message. When a worker only creates new events/messages, use NewEvent. Use this function for the 'extract' worker type.

func (Config) Produce

func (c Config) Produce(msg Message) error

Produce puts the Message with changed Message content and acks the message so it is removed from the queue. Use this function for the 'transform' worker type.

type Message

type Message struct {
	Ref     Reference
	Content string
}

type Reference

type Reference struct {
	AckID   string `json:"ack_id"`
	EventId string `json:"event_id"`
	FlowId  string `json:"flow_id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL