producer

package module
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: Apache-2.0 Imports: 14 Imported by: 4

README

component-producer - Settings component for publishing events to streams

GoDoc Build Status codecov.io

Overview

This is a settings that enables constructing a an event producer. The resulting client may be either an HTTP client provided by component-httpclient or benthos. We use this, for example, to enable migration to and from servers and serverless deployment models for our event stream producers. When running on servers we run benthos as part of a pod or docker compose and use the HTTP option to send events from our app to the benthos process. When running in serverless we statically bind the benthos functionality to the app by using the benthos option.

Quick Start

package main

import (
    "context"

    producer "github.com/asecurityteam/component-producer"
    "github.com/asecurityteam/settings"
)

func main() {
    ctx := context.Background()
    envSource := settings.NewEnvSource(os.Environ())

    p := producer.New(ctx, envSource)
    tr := components.NewHTTP(ctx, envSource)
}

Status

This project is in incubation which means we are not yet operating this tool in production and the interfaces are subject to change.

Contributing

Building And Testing

We publish a docker image called SDCLI that bundles all of our build dependencies. It is used by the included Makefile to help make building and testing a bit easier. The following actions are available through the Makefile:

  • make dep

    Install the project dependencies into a vendor directory

  • make lint

    Run our static analysis suite

  • make test

    Run unit tests and generate a coverage artifact

  • make integration

    Run integration tests and generate a coverage artifact

  • make coverage

    Report the combined coverage for unit and integration tests

License

This project is licensed under Apache 2.0. See LICENSE.txt for details.

Contributing Agreement

Atlassian requires signing a contributor's agreement before we can accept a patch. If you are an individual you can fill out the individual CLA. If you are contributing on behalf of your company then please fill out the corporate CLA.

Documentation

Index

Constants

View Source
const (
	// TypeBenthos is used to select a Benthos producer.
	TypeBenthos = "BENTHOS"
	// TypePOST is used to select an HTTP POST client.
	TypePOST = "POST"
	// TypeNull is used to disable event production.
	TypeNull = "NULL"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BenthosComponent

type BenthosComponent struct{}

BenthosComponent is a component for creating a Benthos producer.

func NewBenthosComponent

func NewBenthosComponent() *BenthosComponent

NewBenthosComponent generates a ProducerBenthosComponent and populates it with defaults

func (*BenthosComponent) New

New constructs a benthos producer.

func (*BenthosComponent) Settings

func (*BenthosComponent) Settings() *BenthosConfig

Settings returns the default configuration.

type BenthosConfig

type BenthosConfig struct {
	YAML string `description:"The YAML or JSON text of a Benthos configuration."`
}

BenthosConfig adapts the Benthos configuration system to this one.

func (*BenthosConfig) Name

func (*BenthosConfig) Name() string

Name of the configuration section.

type Component added in v0.2.0

type Component struct {
	Benthos *BenthosComponent
	POST    *POSTComponent
	Null    *NullComponent
}

Component is the top level producer component.

func NewComponent added in v0.2.0

func NewComponent() *Component

NewComponent populates a ProducerComponent with defaults.

func (*Component) New added in v0.2.0

func (c *Component) New(ctx context.Context, conf *Config) (Producer, error)

New constructs a Producer from the given configuration.

func (*Component) Settings added in v0.2.0

func (c *Component) Settings() *Config

Settings generates a default configuration.

type Config added in v0.2.0

type Config struct {
	Type    string `default:"The type of producer. The choices are BENTHOS and POST."`
	Benthos *BenthosConfig
	POST    *POSTConfig
	Null    *NullConfig
}

Config wraps all producer related configuration.

func (*Config) Name added in v0.2.0

func (*Config) Name() string

Name of the configuration.

type NullComponent added in v0.3.0

type NullComponent struct{}

NullComponent is a component for creating an HTTP POST producer.

func NewNullComponent added in v0.3.0

func NewNullComponent() *NullComponent

NewNullComponent populates a NullComponentt with defaults.

func (*NullComponent) New added in v0.3.0

func (c *NullComponent) New(ctx context.Context, conf *NullConfig) (Producer, error)

New constructs a benthos configuration.

func (*NullComponent) Settings added in v0.3.0

func (c *NullComponent) Settings() *NullConfig

Settings returns the default configuration.

type NullConfig added in v0.3.0

type NullConfig struct{}

NullConfig contains settings for the Null producer.

func (*NullConfig) Name added in v0.3.0

func (*NullConfig) Name() string

Name of the configuration section.

type POSTComponent

type POSTComponent struct {
	HTTP *httpclient.Component
}

POSTComponent is a component for creating an HTTP POST producer.

func NewPOSTComponent

func NewPOSTComponent() *POSTComponent

NewPOSTComponent populates a ProducerPOSTComponent with defaults.

func (*POSTComponent) New

func (c *POSTComponent) New(ctx context.Context, conf *POSTConfig) (Producer, error)

New constructs a benthos configuration.

func (*POSTComponent) Settings

func (c *POSTComponent) Settings() *POSTConfig

Settings returns the default configuration.

type POSTConfig

type POSTConfig struct {
	Endpoint   string `description:"The URL to POST."`
	HTTPClient *httpclient.Config
}

POSTConfig contains settings for the HTTP POST producer.

func (*POSTConfig) Name

func (*POSTConfig) Name() string

Name of the configuration section.

type Producer

type Producer interface {
	// Produce ships the event to the destination and returns the final
	// version of the data sent.
	Produce(ctx context.Context, event interface{}) (interface{}, error)
}

Producer is the interface used for sending all events to a destination.

func Load added in v0.2.0

func Load(ctx context.Context, source settings.Source, c *Component) (Producer, error)

Load is a convenience method for binding the source to the component.

func New added in v0.2.0

func New(ctx context.Context, source settings.Source) (Producer, error)

New is the top-level entry point for creating a producer client.

Jump to

Keyboard shortcuts

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