當前位置: 首頁>>代碼示例>>Python>>正文


Python zmq.XPUB屬性代碼示例

本文整理匯總了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 
開發者ID:benhoff,項目名稱:vexbot,代碼行數:23,代碼來源:messaging.py

示例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) 
開發者ID:timeflux,項目名稱:timeflux,代碼行數:22,代碼來源:zmq.py

示例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" 
開發者ID:DigitalPhonetics,項目名稱:adviser,代碼行數:61,代碼來源:service.py


注:本文中的zmq.XPUB屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。