Python zmq.XPUB Examples
The following are 5
code examples of zmq.XPUB().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
zmq
, or try the search function
.
Example #1
Source File: messaging.py From vexbot with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: zmq.py From timeflux with MIT License | 6 votes |
def __init__( self, address_in="tcp://127.0.0.1:5559", address_out="tcp://127.0.0.1:5560", timeout=5, ): self._timeout = timeout try: # Capture address_monitor = "inproc://monitor" context = zmq.Context.instance() self._monitor = context.socket(zmq.PULL) self._monitor.bind(address_monitor) # Proxy proxy = ThreadProxy(zmq.XSUB, zmq.XPUB, zmq.PUSH) proxy.bind_in(address_in) proxy.bind_out(address_out) proxy.connect_mon(address_monitor) # proxy.setsockopt_mon(zmq.CONFLATE, True) # Do not clutter the network proxy.start() except zmq.ZMQError as error: self.logger.error(error)
Example #3
Source File: zmq.py From timeflux with MIT License | 6 votes |
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)
Example #4
Source File: zmq.py From timeflux with MIT License | 5 votes |
def __init__( self, address_in="tcp://127.0.0.1:5559", address_out="tcp://127.0.0.1:5560" ): """ Initialize frontend and backend. If used on a LAN, bind to tcp://*:5559 and tcp://*:5560 instead of localhost. """ try: context = zmq.Context.instance() self._frontend = context.socket(zmq.XSUB) self._frontend.bind(address_in) self._backend = context.socket(zmq.XPUB) self._backend.bind(address_out) except zmq.ZMQError as e: self.logger.error(e)
Example #5
Source File: service.py From adviser with GNU General Public License v3.0 | 4 votes |
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"