pubsub

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultLibp2pPubSubMaxMessageSize 是 pub-sub 的默认最大消息大小。
	DefaultLibp2pPubSubMaxMessageSize = 50 << 20

	// DefaultPubsubProtocol 默认 dep2p 订阅协议
	DefaultPubsubProtocol = "/dep2p/pubsub/1.0.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DeP2PPubSub

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

DeP2PPubSub 是一个 pub-sub 服务实现。

func NewPubsub

func NewPubsub(ctx context.Context, host host.Host) (*DeP2PPubSub, error)

NewPubsub 创建一个新的 LibP2pPubSub 实例。

func (*DeP2PPubSub) BroadcastWithTopic

func (bps *DeP2PPubSub) BroadcastWithTopic(topic string, data []byte) error

BroadcastWithTopic 方法将消息广播到给定链ID的目标链中的给定主题

func (*DeP2PPubSub) CancelPubsubWithTopic

func (bps *DeP2PPubSub) CancelPubsubWithTopic(name string) error

CancelPubsubWithTopic 取消给定名字的订阅

func (*DeP2PPubSub) CancelSubscribeWithTopic

func (bps *DeP2PPubSub) CancelSubscribeWithTopic(topic string) error

CancelSubscribeWithTopic 取消订阅给定主题

func (*DeP2PPubSub) GetTopic

func (ps *DeP2PPubSub) GetTopic(name string) (*pubsub.Topic, error)

GetTopic 根据给定的名称获取一个 topic。

func (*DeP2PPubSub) IsSubscribed

func (bps *DeP2PPubSub) IsSubscribed(topic string) bool

isSubscribed 方法检查给定的链ID和主题是否已经订阅

func (*DeP2PPubSub) ListPeers

func (bps *DeP2PPubSub) ListPeers(topic string) []peer.ID

ListPeers 返回我们在给定主题中连接到的对等点列表。

func (*DeP2PPubSub) Publish

func (bps *DeP2PPubSub) Publish(topic string, data []byte) error

Publish 向 topic 发布一条消息。

func (*DeP2PPubSub) Pubsub

func (bps *DeP2PPubSub) Pubsub() *pubsub.PubSub

Pubsub 返回 pubsub.PubSub 实例

func (*DeP2PPubSub) Start

func (bps *DeP2PPubSub) Start(opts ...pubsub.Option) error

Start 方法用于启动 pub-sub 服务。 它首先检查主机是否正在运行,然后检查 pub-sub 服务是否已经启动。如果 pub-sub 服务尚未启动,它会设置启动状态为 1 并启动 pub-sub 服务。如果在启动过程中出现错误,它会返回错误。否则,它会将新创建的 pub-sub 服务赋值给 ps.pubsub,并将启动状态设置为 2。

func (*DeP2PPubSub) Subscribe

func (bps *DeP2PPubSub) Subscribe(topic string, subscribe bool) (*pubsub.Subscription, error)

Subscribe 订阅一个 topic。

func (*DeP2PPubSub) SubscribeWithTopic

func (bps *DeP2PPubSub) SubscribeWithTopic(topic string, handler PubSubMsgHandler, subscribe bool) error

SubscribeWithTopic 订阅给定链ID的目标链中的给定主题,并使用给定的订阅消息处理函数。

type PubSubMsgHandler

type PubSubMsgHandler func(*streams.RequestMessage)

PubSubMsgHandler handle the msg published by other node.

Jump to

Keyboard shortcuts

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