Esempio n. 1
0
    def find_old(self, domain, subject, tip):
        result = list()

        for k in self.db_old:
            topic = xMsgTopic.wrap(k)
            if ((topic.domain() == domain) and
                (topic.subject() == subject or
                 subject == "undefined" or subject == "*") and
                (topic.type() == tip or
                 tip == "undefined" or tip == "*")):
                result.append(self.db_old[k])
        return result
Esempio n. 2
0
    def sync_publish(self, connection, transient_message, timeout):
        """Publishes a message through the specified proxy connection and
        blocks waiting for a response.

        The subscriber must publish the response to the topic given by the
        reply_to metadata field, through the same proxy.

        This method will throw if a response is not received before the timeout
        expires.

        Args:
            connection (xMsgProxyDriver): proxy connection driver
            transient_message (xMsgMessage): transient message
            timeout (int): timeout for reply in seconds
        """

        # set the return address as replyTo in the xMsgMessage
        return_address = "return: %d" % randint(0, 10000)
        transient_message.set_reply_topic(return_address)

        # subscribe to the return_address
        sync_callback = _SyncSendCallBack()
        subscription = self.subscribe(connection.get_address(),
                                      xMsgTopic.wrap(return_address),
                                      sync_callback, 1)
        sync_callback.set_handler(subscription)

        self.publish(connection, transient_message)
        # wait for the response
        time_counter = 0

        while not sync_callback.received_message:
            try:
                if time_counter >= timeout * 1000:
                    self.unsubscribe(subscription)
                    raise Exception("Error: time_out reached - %d" %
                                    time_counter)

                else:
                    time_counter += 1
                xMsgUtil.sleep(0.001)
            except zmq.error.ZMQError as e:
                self.unsubscribe(subscription)
                print e.message

        self.unsubscribe(subscription)
        return sync_callback.received_message
def runner(bind_to, message_size, message_count):
    pub_node_addr = xMsgAddress(bind_to)
    publisher = Publisher(bind_to, message_size, message_count)
    pub_connection = publisher.get_new_connection(pub_node_addr)
    topic = xMsgTopic.wrap("thr_topic")

    try:
        data = bytes(b'\x00' * message_size)
        for _ in range(message_count):
            t_msg = xMsgMessage()
            t_msg.set_topic(topic)
            t_msg.set_data(bytes(data), "data/binary")
            publisher.publish(pub_connection, t_msg)
        publisher.destroy()

    except Exception as e:
        print "Removing publisher..."
        publisher.destroy()
        return

    return
def local_runner(bind_to, size_message, n_messages, csv_flag=False):
    subscriber = Subscriber(bind_to, csv_flag)

    pub_node = xMsgAddress(bind_to)
    connection = subscriber.get_new_connection(pub_node)
    topic = xMsgTopic.wrap("thr_topic")

    condition = Condition()
    callback = THRCallBack(csv_flag, n_messages, size_message, condition)
    try:
        subscription = subscriber.subscribe(connection, topic, callback)

        with condition:
            condition.wait()
        callback.write()
    except:
        print "Exiting..."
    finally:
        subscriber.unsubscribe(subscription)
        subscriber.destroy()
        return
 def setUp(self):
     self.topic = xMsgTopic.wrap("a:b:c")
     self.message = xMsgMessage(self.topic, bytes([1, 2, 3]))
Esempio n. 6
0
 def get_reply_topic(self):
     return xMsgTopic.wrap(self._metadata.replyTo)
Esempio n. 7
0
 def test_is_parent_method(self):
     topic_parent = xMsgTopic.wrap("domain:subject")
     topic = xMsgTopic.wrap("domain:subject:type1")
     self.assertTrue(topic_parent.is_parent(topic))
Esempio n. 8
0
 def _report(self, topic_prefix, engine_data):
     topic = xMsgTopic.wrap(str(topic_prefix) + ":" + self.myname)
     msg = self.serialize(topic, engine_data,
                          self._engine_object.get_output_data_types())
     self.send_frontend(msg)