ezmq

package
v0.0.0-...-806d39f Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

EZMQ package which provides simplified APIs for Publisher and Subscriber.

Index

Constants

View Source
const (
	EZMQ_CONTENT_TYPE_PROTOBUF = 0
	EZMQ_CONTENT_TYPE_BYTEDATA = 1
	EZMQ_CONTENT_TYPE_AML      = 2 // Not in use as of now
	EZMQ_CONTENT_TYPE_JSON     = 3 // Not in use as of now
)

Constants represents EZMQ content types.

View Source
const (
	EZMQ_OK                   = 0
	EZMQ_ERROR                = 1
	EZMQ_INVALID_TOPIC        = 2
	EZMQ_INVALID_CONTENT_TYPE = 3
)

Constants represents EZMQ error codes.

View Source
const (
	EZMQ_Unknown     = 0
	EZMQ_Constructed = 1
	EZMQ_Initialized = 2
	EZMQ_Terminated  = 3
)

Constants represents EZMQ Status codes.

View Source
const INPROC_PREFIX = "inproc://shutdown-"
View Source
const PUB_KEY_LENGTH = 40

Publisher key length

View Source
const PUB_TCP_PREFIX = "tcp://*:"

Address Prefix for Publisher.

View Source
const SUB_KEY_LENGTH = 40

Subscriber key length

View Source
const SUB_TCP_PREFIX = "tcp://"

Address prefix to bind subscriber.

View Source
const TOPIC_PATTERN = "^[a-zA-Z0-9-_./]+$"

Regex Pattern for Topic validation.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger()

Types

type EZMQAPI

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

Structure represents EZMQAPI

func GetInstance

func GetInstance() *EZMQAPI

Get EZMQAPI instance.

func (*EZMQAPI) GetContext

func (ezmqInstance *EZMQAPI) GetContext() *zmq.Context

func (*EZMQAPI) GetStatus

func (ezmqInstance *EZMQAPI) GetStatus() EZMQStatusCode

func (*EZMQAPI) Initialize

func (ezmqInstance *EZMQAPI) Initialize() EZMQErrorCode

Initialize required EZMQ components. This API should be called first, before using any EZMQ APIs.

func (*EZMQAPI) Terminate

func (ezmqInstance *EZMQAPI) Terminate() EZMQErrorCode

Perform cleanup of EZMQ components.

type EZMQByteData

type EZMQByteData struct {
	ByteData []byte
}

Structure represents EZMQByteData.

func (*EZMQByteData) GetByteData

func (dataInstance *EZMQByteData) GetByteData() []byte

Get byte data

func (EZMQByteData) GetContentType

func (dataInstance EZMQByteData) GetContentType() EZMQContentType

Get Content type

func (*EZMQByteData) SetByteData

func (dataInstance *EZMQByteData) SetByteData(byteData []byte) EZMQErrorCode

set byte data

type EZMQContentType

type EZMQContentType int

type EZMQErrorCB

type EZMQErrorCB func(code EZMQErrorCode)

Error Callback for start/stop of EZMQ publisher. [As of now, Not being used]

type EZMQErrorCode

type EZMQErrorCode int

type EZMQMessage

type EZMQMessage interface {
	GetContentType() EZMQContentType
}

Interface for ezmq message.

type EZMQPublisher

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

Structure represents EZMQPublisher.

func GetEZMQPublisher

func GetEZMQPublisher(port int, startCallback EZMQStartCB, stopCallback EZMQStopCB, errorCallback EZMQErrorCB) *EZMQPublisher

Constructs EZMQPublisher.

func (*EZMQPublisher) GetPort

func (pubInstance *EZMQPublisher) GetPort() int

Get publisher port.

func (*EZMQPublisher) Publish

func (pubInstance *EZMQPublisher) Publish(ezmqMsg EZMQMessage) EZMQErrorCode

Publish events on the socket for subscribers.

func (*EZMQPublisher) PublishOnTopic

func (pubInstance *EZMQPublisher) PublishOnTopic(topic string, ezmqMsg EZMQMessage) EZMQErrorCode

Publish events on a specific topic on socket for subscribers.

Note: (1) Topic name should be as path format. For example:home/livingroom/

(2) Topic name can have letters [a-z, A-z], numerics [0-9] and special characters _ - / and .

func (*EZMQPublisher) PublishOnTopicList

func (pubInstance *EZMQPublisher) PublishOnTopicList(topicList List.List, ezmqMsg EZMQMessage) EZMQErrorCode

Publish an events on list of topics on socket for subscribers. On any of the topic in list, if it failed to publish event it will return EZMQ_ERROR/EZMQ_INVALID_TOPIC.

Note: (1) Topic name should be as path format. For example:home/livingroom/

(2) Topic name can have letters [a-z, A-z], numerics [0-9] and special characters _ - / and .

func (*EZMQPublisher) SetServerPrivateKey

func (pubInstance *EZMQPublisher) SetServerPrivateKey(key []byte) EZMQErrorCode

Set the server private/secret key.

Note: (1) Key should be 40-character string encoded in the Z85 encoding format

(2) This API should be called before start() API.

func (*EZMQPublisher) Start

func (pubInstance *EZMQPublisher) Start() EZMQErrorCode

Starts PUB instance.

func (*EZMQPublisher) Stop

func (pubInstance *EZMQPublisher) Stop() EZMQErrorCode

Stops PUB instance.

type EZMQStartCB

type EZMQStartCB func(code EZMQErrorCode)

Callback to get error code for start of EZMQ publisher. [As of now, Not being used]

type EZMQStatusCode

type EZMQStatusCode int

type EZMQStopCB

type EZMQStopCB func(code EZMQErrorCode)

Callback to get error code for stop of EZMQ publisher. [As of now, Not being used]

type EZMQSubCB

type EZMQSubCB func(event EZMQMessage)

Callback to get all the subscribed events.

type EZMQSubTopicCB

type EZMQSubTopicCB func(topic string, event EZMQMessage)

Callback to get all the subscribed events for a specific topic.

type EZMQSubscriber

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

Structure represents EZMQSubscriber.

func GetEZMQSubscriber

func GetEZMQSubscriber(ip string, port int, subCallback EZMQSubCB, subTopicCallback EZMQSubTopicCB) *EZMQSubscriber

Constructs EZMQSubscriber.

func (*EZMQSubscriber) GetIP

func (subInstance *EZMQSubscriber) GetIP() string

Get Ip of publisher to which subscribed.

func (*EZMQSubscriber) GetPort

func (subInstance *EZMQSubscriber) GetPort() int

Get Port of publisher to which subscribed.

func (*EZMQSubscriber) SetClientKeys

func (subInstance *EZMQSubscriber) SetClientKeys(clientPrivateKey []byte, clientPublicKey []byte) EZMQErrorCode

Set the security keys of client/its own.

Note: (1) Key should be 40-character string encoded in the Z85 encoding format <br>

(2) This API should be called before start() API.

func (*EZMQSubscriber) SetServerPublicKey

func (subInstance *EZMQSubscriber) SetServerPublicKey(key []byte) EZMQErrorCode

Set the server public key.

Note: (1) Key should be 40-character string encoded in the Z85 encoding format <br>

(2) This API should be called before start() API.

(3) If using the following API in secured mode:

SubscribeWithIPPort(ip string, port int, topic string) EZMQErrorCode
SetServerPublicKey API needs to be called before that.

func (*EZMQSubscriber) Start

func (subInstance *EZMQSubscriber) Start() EZMQErrorCode

Starts SUB instance.

func (*EZMQSubscriber) Stop

func (subInstance *EZMQSubscriber) Stop() EZMQErrorCode

Stops SUB instance.

func (*EZMQSubscriber) Subscribe

func (subInstance *EZMQSubscriber) Subscribe() EZMQErrorCode

Subscribe for event/messages.

func (*EZMQSubscriber) SubscribeForTopic

func (subInstance *EZMQSubscriber) SubscribeForTopic(topic string) EZMQErrorCode

Subscribe for event/messages on a particular topic.

func (*EZMQSubscriber) SubscribeForTopicList

func (subInstance *EZMQSubscriber) SubscribeForTopicList(topicList List.List) EZMQErrorCode

Subscribe for event/messages on given list of topics. On any of the topic in list, if it failed to subscribe events it will return EZMQ_ERROR/EZMQ_INVALID_TOPIC.

Note: (1) Topic name should be as path format. For example:home/livingroom/

(2) Topic name can have letters [a-z, A-z], numerics [0-9] and special characters _ - / and .

func (*EZMQSubscriber) SubscribeWithIPPort

func (subInstance *EZMQSubscriber) SubscribeWithIPPort(ip string, port int, topic string) EZMQErrorCode

Subscribe for event/messages from given IP:Port on the given topic.

Note: (1) It will be using same Subscriber socket for connecting to given ip:port.

(2) To un-subcribe use un-subscribe API with the same topic.

(3) Topic name should be as path format. For example:home/livingroom/

(4) Topic name can have letters [a-z, A-z], numeric [0-9] and special characters _ - / and .

(5) Topic will be appended with forward slash [/] in case, if application has not appended it.

(6) If using in secured mode: Call setServerPublicKey API with target server public key before calling this API.

func (*EZMQSubscriber) UnSubscribe

func (subInstance *EZMQSubscriber) UnSubscribe() EZMQErrorCode

Un-subscribe all the events from publisher.

func (*EZMQSubscriber) UnSubscribeForTopic

func (subInstance *EZMQSubscriber) UnSubscribeForTopic(topic string) EZMQErrorCode

Un-subscribe specific topic events.

Note: (1) Topic name should be as path format. For example:home/livingroom/

(2) Topic name can have letters [a-z, A-z], numerics [0-9] and special characters _ - / and .

func (*EZMQSubscriber) UnSubscribeForTopicList

func (subInstance *EZMQSubscriber) UnSubscribeForTopicList(topicList List.List) EZMQErrorCode

Un-subscribe event/messages on given list of topics. On any of the topic in list, if it failed to unsubscribe events it will return EZMQ_ERROR/EZMQ_INVALID_TOPIC.

Note: (1) Topic name should be as path format. For example:home/livingroom/ .

(2) Topic name can have letters [a-z, A-z], numerics [0-9] and special characters _ - / and .

type Event

type Event struct {
	Id               *string    `protobuf:"bytes,1,req,name=id" json:"id,omitempty"`
	Created          *int64     `protobuf:"varint,2,req,name=created" json:"created,omitempty"`
	Modified         *int64     `protobuf:"varint,3,req,name=modified" json:"modified,omitempty"`
	Origin           *int64     `protobuf:"varint,4,req,name=origin" json:"origin,omitempty"`
	Pushed           *int64     `protobuf:"varint,5,req,name=pushed" json:"pushed,omitempty"`
	Device           *string    `protobuf:"bytes,6,req,name=device" json:"device,omitempty"`
	Reading          []*Reading `protobuf:"bytes,7,rep,name=reading" json:"reading,omitempty"`
	XXX_unrecognized []byte     `json:"-"`
}

func (*Event) Descriptor

func (*Event) Descriptor() ([]byte, []int)

func (Event) GetContentType

func (m Event) GetContentType() EZMQContentType

This method is added specifically for ezmq message.

func (*Event) GetCreated

func (m *Event) GetCreated() int64

func (*Event) GetDevice

func (m *Event) GetDevice() string

func (*Event) GetId

func (m *Event) GetId() string

func (*Event) GetModified

func (m *Event) GetModified() int64

func (*Event) GetOrigin

func (m *Event) GetOrigin() int64

func (*Event) GetPushed

func (m *Event) GetPushed() int64

func (*Event) GetReading

func (m *Event) GetReading() []*Reading

func (*Event) ProtoMessage

func (*Event) ProtoMessage()

func (*Event) Reset

func (m *Event) Reset()

func (*Event) String

func (m *Event) String() string

type Reading

type Reading struct {
	Id               *string `protobuf:"bytes,1,req,name=id" json:"id,omitempty"`
	Created          *int64  `protobuf:"varint,2,req,name=created" json:"created,omitempty"`
	Modified         *int64  `protobuf:"varint,3,req,name=modified" json:"modified,omitempty"`
	Origin           *int64  `protobuf:"varint,4,req,name=origin" json:"origin,omitempty"`
	Pushed           *int64  `protobuf:"varint,5,req,name=pushed" json:"pushed,omitempty"`
	Name             *string `protobuf:"bytes,6,req,name=name" json:"name,omitempty"`
	Value            *string `protobuf:"bytes,7,req,name=value" json:"value,omitempty"`
	Device           *string `protobuf:"bytes,8,req,name=device" json:"device,omitempty"`
	XXX_unrecognized []byte  `json:"-"`
}

func (*Reading) Descriptor

func (*Reading) Descriptor() ([]byte, []int)

func (*Reading) GetCreated

func (m *Reading) GetCreated() int64

func (*Reading) GetDevice

func (m *Reading) GetDevice() string

func (*Reading) GetId

func (m *Reading) GetId() string

func (*Reading) GetModified

func (m *Reading) GetModified() int64

func (*Reading) GetName

func (m *Reading) GetName() string

func (*Reading) GetOrigin

func (m *Reading) GetOrigin() int64

func (*Reading) GetPushed

func (m *Reading) GetPushed() int64

func (*Reading) GetValue

func (m *Reading) GetValue() string

func (*Reading) ProtoMessage

func (*Reading) ProtoMessage()

func (*Reading) Reset

func (m *Reading) Reset()

func (*Reading) String

func (m *Reading) String() string

Jump to

Keyboard shortcuts

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