file

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Example (Plugin)
package main

import (
	"context"
	"io/ioutil"
	"os"
	"time"

	plugin "github.com/LeKovr/mqbridge/plugins/file"
	"github.com/LeKovr/mqbridge/types"
)

const (
	TestRow0 = "test row one"
	TestRow1 = "test row two"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	epa := types.NewBlankEndPointAttr(ctx)
	plug, _ := plugin.New(epa, "test")
	pipe := make(chan string)
	file, _ := ioutil.TempFile(".", "mqbridge-test-in")
	defer os.Remove(file.Name())
	file.WriteString(TestRow0 + "\n")
	plug.Listen(0, file.Name(), pipe)
	plug.Notify(0, "-", pipe)
	file.WriteString(TestRow1 + "\n")
	time.Sleep(100 * time.Millisecond)
	cancel()
	epa.WG.Wait()
}
Output:

test row one
test row two

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(epa types.EndPointAttr, dsn string) (types.EndPoint, error)

New creates endpoint

Types

type EndPoint

type EndPoint struct {
	types.EndPointAttr
}

EndPoint holds endpoint

func (EndPoint) Listen

func (ep EndPoint) Listen(id int, channel string, pipe chan string) error

Listen starts all listening goroutines

func (EndPoint) Notify

func (ep EndPoint) Notify(id int, channel string, pipe chan string) error

Notify starts all notify goroutines

Jump to

Keyboard shortcuts

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