Documentation ¶
Index ¶
- Constants
- Variables
- type EventChannel
- type Message
- type NodeRole
- type PubSubError
- type PubSubLogger
- type PubSubManager
- func (pubSubManager *PubSubManager) AddTopic(topic string)
- func (pubSubManager *PubSubManager) HasTopic(topic string) bool
- func (pubSubManager *PubSubManager) PublishMessage(message *Message)
- func (pubSubManager *PubSubManager) RegisterNewSubscriber(topic string) (uint, EventChannel, error)
- func (pubSubManager *PubSubManager) Start()
- func (pubSubManager *PubSubManager) Unsubscribe(topic string, subId uint)
Constants ¶
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
const ( UnexpectedError = iota UnmashallJsonError MashallJsonError UnregisteredTopicError )
const ChanWorkLoad = 100
Variables ¶
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"}, }
var Logger = PubSubLogger{}
Global instant to use
var Topics = []string{ NewShardblockTopic, NewBeaconBlockTopic, MempoolInfoTopic, TestTopic, TransactionHashEnterNodeTopic, ShardRoleTopic, BeaconRoleTopic, NodeRoleDetailTopic, BeaconBeststateTopic, RequestBeaconBlockByHashTopic, RequestBeaconBlockByHeightTopic, RequestShardBlockByHeightTopic, RequestShardBlockByHashTopic, ShardBeststateTopic, }
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 ¶
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)