broker

package
v0.0.0-...-e964040 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Connect .
	Connect() error
	// Disconnect .
	Disconnect() error
	// Publish 消息发布
	Publish(topic string, v interface{}, opts ...PublishOption) error
	// Subscribe 消息订阅
	Subscribe(topic string, handler Handler, otps ...SubscribeOption)
	// Type .
	Type() Type
}

Client .

type Event

type Event interface {
	// Topic .
	Topic() string
	// Body return bytes of Message.Data
	Body() []byte
	// Unmarshal unmarshal for Message.Data. must be a pointer
	Unmarshal(v interface{}) error
}

Event .

type Handler

type Handler func(event Event) error
type Header map[string]string

type Message

type Message struct {
	// ID topic 唯一标识符 16字节
	ID uuid.UUID `json:"id"`
	// Topic subject
	Topic string `json:"topic"`
	// Producer .
	Producer string `json:"producer"`
	// CreatedAt 创建时间
	CreatedAt string `json:"created_at"`
	// ContentType 编码类型 application/json | application/proto
	ContentType content.Type `json:"content_type"`
	// Data .
	Data interface{} `json:"data"`
}

Message .

type Option

type Option func(o *Options)

func Address

func Address(address string) Option

Address .

func Debug

func Debug(debug bool) Option

Debug .

func ReconnectTime

func ReconnectTime(d int) Option

ReconnectTime 重连等待时间。单位:秒

type Options

type Options struct {
	// Address adress
	Address string
	// ReconnectTime 重连等待时间。单位:秒
	ReconnectTime time.Duration
	// Debug print message
	Debug bool
}

Options .

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions .

type PublishOption

type PublishOption func(o *PublishOptions)

func PublishJson

func PublishJson(opts ...func(o *codec.MarshalOptions)) PublishOption

PublishJson .

func PublishProto

func PublishProto(opts ...func(o *codec.MarshalOptions)) PublishOption

PublishProto .

type PublishOptions

type PublishOptions struct {
	// Codec 序列化方式. default codec.MarshalerType_Json
	Codec codec.Marshaler
}

PublishOptions .

func DefaultPublishOptions

func DefaultPublishOptions() *PublishOptions

DefaultPublishOptions .

type SubscribeOption

type SubscribeOption func(o *SubscribeOptions)

func SubscribeContext

func SubscribeContext(c context.Context) SubscribeOption

SubscribeContext .

func SubscribeJson

func SubscribeJson() SubscribeOption

SubscribeJson .

func SubscribeProto

func SubscribeProto() SubscribeOption

SubscribeProto .

type SubscribeOptions

type SubscribeOptions struct {
	// Context ctx
	Context context.Context
	// Codec 序列化方式. default codec.MarshalerType_Json
	Codec codec.Marshaler
}

SubscribeOptions .

func DefaultSubscribeOptions

func DefaultSubscribeOptions() *SubscribeOptions

DefaultSubscribeOptions .

type Type

type Type string
const (
	// TypeNats nats
	TypeNats Type = "nats"
	// TypeKafka kafka
	TypeKafka Type = "kafka"
)

func (Type) String

func (t Type) String() string

String .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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