subscribe

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Example (Kafka)
var sub = NewKafkaSubscriber(context.Background(), KafkaConfig{
	Hosts:       []string{"localhost:3096"},
	PartitionID: 0,
	Topic:       "topic-test",
})
_ = sub.Run()
defer sub.Close()

messageChan, _ := sub.Get()

for message := range messageChan {
	var m Message
	_ = json.Unmarshal(message, &m)
}
Output:

Example (Ws)
var sub = NewWsSubscriber(context.Background(), WsConfig{
	Addr: "localhost:8080",
	Path: "/ws-test",
})
_ = sub.Run()
defer sub.Close()

messageChan, _ := sub.Get()

for message := range messageChan {
	var m Message
	_ = json.Unmarshal(message, &m)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeConfig

type FakeConfig struct {
	PublishSend <-chan []byte
}

type KafkaConfig

type KafkaConfig struct {
	Hosts []string

	// One consumer should bind to one partition.
	PartitionID int32
	Topic       string
}

type Subscribe

type Subscribe interface {
	// Get use key to recognize messages what I need.
	// Note that data is recommended to design into a struct include a string key and a bytes type data.
	Get() (<-chan []byte, error)
	Run() error
	Close() error
}

func NewFakeSubscriber

func NewFakeSubscriber(config FakeConfig) Subscribe

func NewKafkaSubscriber

func NewKafkaSubscriber(ctx context.Context, config KafkaConfig) Subscribe

func NewWsSubscriber

func NewWsSubscriber(ctx context.Context, config WsConfig) Subscribe

type WsConfig

type WsConfig struct {
	Addr string
	Path string
}

Jump to

Keyboard shortcuts

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