pubsub

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	NewShardblockTopic              = "newshardblocktopic"
	NewBeaconBlockTopic             = "newbeaconblocktopic"
	TransactionHashEnterNodeTopic   = "transactionhashenternodetopic"
	ShardRoleTopic                  = "shardroletopic"
	BeaconRoleTopic                 = "beaconroletopic"
	NodeRoleDetailTopic             = "noderoledetailtopic"
	MempoolInfoTopic                = "mempoolinfotopic"
	BeaconBeststateTopic            = "beaconbeststatetopic"
	ShardBeststateTopic             = "shardbeststatetopic"
	RequestShardBlockByHashTopic    = "requestshardblockbyhashtopic"
	RequestShardBlockByHeightTopic  = "requestshardblockbyheighttopic"
	RequestBeaconBlockByHeightTopic = "requestbeaconblockbyheighttopic"
	RequestBeaconBlockByHashTopic   = "requestbeaconblockbyhashtopic"
	TestTopic                       = "testtopic"
)

TOPIC

View Source
const (
	UnexpectedError = iota
	UnmashallJsonError
	MashallJsonError
	UnregisteredTopicError
)
View Source
const ChanWorkLoad = 100

Variables

View Source
var ErrCodeMessage = map[int]struct {
	Code    int
	Message string
}{
	UnexpectedError:        {-1000, "Unexpected Error"},
	UnmashallJsonError:     {-1001, "Umarshall Json Error"},
	MashallJsonError:       {-1002, "Marshall Json Error"},
	UnregisteredTopicError: {-1003, "Subcribed Topic Not Found Error"},
}
View Source
var Logger = PubSubLogger{}

Global instant to use

Functions

This section is empty.

Types

type EventChannel

type EventChannel chan *Message

func (EventChannel) NotifyMessage

func (event EventChannel) NotifyMessage(message *Message)

type Message

type Message struct {
	Value interface{}
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(topic string, value interface{}) *Message

type NodeRole

type NodeRole struct {
	CID  int
	Role string
}

type PubSubError

type PubSubError struct {
	Code    int    // The code to send with reject messages
	Message string // Human readable message of the issue
	Err     error
}

func NewPubSubError

func NewPubSubError(key int, err error, params ...interface{}) *PubSubError

func (PubSubError) Error

func (e PubSubError) Error() string

Error satisfies the error interface and prints human-readable errors.

func (*PubSubError) Init

func (e *PubSubError) Init(key int, err error)

txRuleError creates an underlying MempoolTxError with the given a set of arguments and returns a RuleError that encapsulates it.

type PubSubLogger

type PubSubLogger struct {
	// contains filtered or unexported fields
}

func (*PubSubLogger) Init

func (metricLogger *PubSubLogger) Init(inst common.Logger)

type PubSubManager

type PubSubManager struct {
	// contains filtered or unexported fields
}

This package provide an Event Channel for internal pub sub of this application It will issue a list of pre-defined topic Publisher will register to be publisher with a particular topic, then it will be able to publish message of this topic into Event Channel Subcriber will register to be Subcribe with a particular topic, when new message of this topic come to Event Channel, then Event Channel will fire this message to subcriber

func NewPubSubManager

func NewPubSubManager() *PubSubManager

func (*PubSubManager) AddTopic

func (pubSubManager *PubSubManager) AddTopic(topic string)

func (*PubSubManager) HasTopic

func (pubSubManager *PubSubManager) HasTopic(topic string) bool

func (*PubSubManager) PublishMessage

func (pubSubManager *PubSubManager) PublishMessage(message *Message)

Publisher public message to EventChannel

func (*PubSubManager) RegisterNewSubscriber

func (pubSubManager *PubSubManager) RegisterNewSubscriber(topic string) (uint, EventChannel, error)

Subcriber register with wanted topic Return Event and Id of that Event Event Channel using event to signal subcriber new message

func (*PubSubManager) Start

func (pubSubManager *PubSubManager) Start()

Forever Loop play as an Event Channel

func (*PubSubManager) Unsubscribe

func (pubSubManager *PubSubManager) Unsubscribe(topic string, subId uint)

Jump to

Keyboard shortcuts

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