Skip to content

ding.framework.message_queue.mq

ding.framework.message_queue.mq

MQ

Overview

Abstract basic mq class.

__init__(*args, **kwargs)

Overview

The init method of the inheritance must support the extra kwargs parameter.

listen()

Overview

Bind to local socket or connect to third party components.

publish(topic, data)

Overview

Send data to mq.

Arguments: - topic (:obj:str): Topic. - data (:obj:bytes): Payload data.

subscribe(topic)

Overview

Subscribe to the topic.

Arguments: - topic (:obj:str): Topic

unsubscribe(topic)

Overview

Unsubscribe from the topic.

Arguments: - topic (:obj:str): Topic

recv()

Overview

Wait for incoming message, this function will block the current thread.

Returns: - data (:obj:Any): The sent payload.

stop()

Overview

Unsubscribe from all topics and stop the connection to the message queue server.

Full Source Code

../ding/framework/message_queue/mq.py

1from typing import Tuple 2 3 4class MQ: 5 """ 6 Overview: 7 Abstract basic mq class. 8 """ 9 10 def __init__(self, *args, **kwargs) -> None: 11 """ 12 Overview: 13 The __init__ method of the inheritance must support the extra kwargs parameter. 14 """ 15 pass 16 17 def listen(self) -> None: 18 """ 19 Overview: 20 Bind to local socket or connect to third party components. 21 """ 22 raise NotImplementedError 23 24 def publish(self, topic: str, data: bytes) -> None: 25 """ 26 Overview: 27 Send data to mq. 28 Arguments: 29 - topic (:obj:`str`): Topic. 30 - data (:obj:`bytes`): Payload data. 31 """ 32 raise NotImplementedError 33 34 def subscribe(self, topic: str) -> None: 35 """ 36 Overview: 37 Subscribe to the topic. 38 Arguments: 39 - topic (:obj:`str`): Topic 40 """ 41 raise NotImplementedError 42 43 def unsubscribe(self, topic: str) -> None: 44 """ 45 Overview: 46 Unsubscribe from the topic. 47 Arguments: 48 - topic (:obj:`str`): Topic 49 """ 50 raise NotImplementedError 51 52 def recv(self) -> Tuple[str, bytes]: 53 """ 54 Overview: 55 Wait for incoming message, this function will block the current thread. 56 Returns: 57 - data (:obj:`Any`): The sent payload. 58 """ 59 raise NotImplementedError 60 61 def stop(self) -> None: 62 """ 63 Overview: 64 Unsubscribe from all topics and stop the connection to the message queue server. 65 """ 66 return