本文整理汇总了Python中zmq.XPUB属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.XPUB属性的具体用法?Python zmq.XPUB怎么用?Python zmq.XPUB使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类zmq
的用法示例。
在下文中一共展示了zmq.XPUB属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _setup_subscription_socket
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import XPUB [as 别名]
def _setup_subscription_socket(self, do_auth=None):
if do_auth is not None:
old_auth = self._socket_factory.using_auth
self._socket_factory.using_auth = do_auth
iter_ = self._socket_factory.iterate_multiple_addresses
sub_addresses = iter_(self.config['chatter_subscription_port'])
# TODO: verify that this shouldn't be like a connect as the socket
# factory defaults to bind subscription socket is a XPUB socket
multiple_create = self._socket_factory.multiple_create_n_connect
name = 'subscription socket'
self.subscription_socket = multiple_create(zmq.XPUB,
sub_addresses,
bind=True,
socket_name=name)
info = self._messaging_logger.subscribe.info
[info(' Address: %s', x) for x in sub_addresses]
if do_auth is not None:
self._socket_factory.using_auth = old_auth
示例2: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import XPUB [as 别名]
def __init__(
self,
address_in="tcp://127.0.0.1:5559",
address_out="tcp://127.0.0.1:5560",
timeout=1000,
):
self._timeout = timeout
try:
context = zmq.Context.instance()
self._frontend = context.socket(zmq.SUB)
self._frontend.setsockopt(zmq.SUBSCRIBE, b"")
self._frontend.bind(address_in)
self._backend = context.socket(zmq.XPUB)
self._backend.setsockopt(zmq.XPUB_VERBOSE, True)
self._backend.bind(address_out)
self._poller = zmq.Poller()
self._poller.register(self._frontend, zmq.POLLIN)
self._poller.register(self._backend, zmq.POLLIN)
except zmq.ZMQError as error:
self.logger.error(error)
示例3: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import XPUB [as 别名]
def __init__(self, domain: Union[str, Domain] = "", sub_topic_domains: Dict[str, str] = {}, pub_topic_domains: Dict[str, str] = {},
ds_host_addr: str = "127.0.0.1", sub_port: int = 65533, pub_port: int = 65534, protocol: str = "tcp",
debug_logger: DiasysLogger = None, identifier: str = None):
"""
Create a new service instance *(call this super constructor from your inheriting classes!)*.
Args:
domain (Union[str, Domain]): The domain(-name) of your service (or empty string, if domain-agnostic).
If a domain(-name) is set, it will automatically filter out all messages from other domains.
If no domain(-name) is set, messages from all domains will be received.
sub_topic_domains (Dict[str, str]): change subscribed to topics to listen to a specific domain
(e.g. 'erase'/append a domain for a specific topic)
pub_topic_domains (Dict[str, str]): change published topics to a specific domain
(e.g. 'erase'/append a domain for a specific topic)
ds_host_addr (str): IP-address of the parent `DialogSystem` (default: localhost)
sub_port (int): subscriber port following zmq's XSUB/XPUB pattern
pub_port (int): publisher port following zmq's XSUB/XPUB pattern
protocol (string): communication protocol with `DialogSystem` - has to match!
Possible options: `tcp`, `inproc`, `ipc`
debug_logger (DiasysLogger): If not `None`, all messags are printed to the logger, including send/receive events.
Can be useful for debugging because you can still see messages received by the `DialogSystem`
even if they are never forwarded (as expected) to your `Service`.
identifier (str): Set this to a *UNIQUE* identifier per service to be run remotely.
See `RemoteService` for more details.
"""
self.is_training = False
self.domain = domain
# get domain name (gets appended to all sub/pub topics so that different domain topics don't get shared)
if domain is not None:
self._domain_name = domain.get_domain_name() if isinstance(domain, Domain) else domain
else:
self._domain_name = ""
self._sub_topic_domains = sub_topic_domains
self._pub_topic_domains = pub_topic_domains
# socket information
self._host_addr = ds_host_addr
self._sub_port = sub_port
self._pub_port = pub_port
self._protocol = protocol
self._identifier = identifier
self.debug_logger = debug_logger
self._sub_topics = set()
self._pub_topics = set()
self._publish_sockets = dict()
self._internal_start_topics = dict()
self._internal_end_topics = dict()
self._internal_terminate_topics = dict()
# NOTE: class name + memory pointer make topic unique (required, e.g. for running mutliple instances of same module!)
self._start_topic = f"{type(self).__name__}/{id(self)}/START"
self._end_topic = f"{type(self).__name__}/{id(self)}/END"
self._terminate_topic = f"{type(self).__name__}/{id(self)}/TERMINATE"
self._train_topic = f"{type(self).__name__}/{id(self)}/TRAIN"
self._eval_topic = f"{type(self).__name__}/{id(self)}/EVAL"