def send(self, payload):
        """
        Method needed for child connection classes to update.
        """
        LOG.debug(
            'Attempting to send connection payload "%s" to address "%s" w/ topic "%s"',
            payload, self.connection_addresses['publisher'], self.topic)

        if self.topic:
            to_send = msg_pack(self.topic) + msg_pack(payload)
        else:
            to_send = msg_pack(payload)

        self.socket.send(to_send)
        LOG.debug('Sent payload!')
예제 #2
0
 def return_to_requester(self, payload):
     """
     This method is passed with the socket for when a new message is recieved
     for the replyer socket.
     """
     LOG.debug('Sending Return Payload...')
     self.socket.send(msg_pack(payload))
def test_msgpack_utils__msg_pack__will_pack_and_unpack_numpy_ndarray():
    """
    Make sure the function can pack and unpack a numpy ndarray
    """
    to_test = {'regular_key': 'Hii', 'numpy.ndarray': numpy.ndarray([1])}

    encoded = msgpack_utils.msg_pack(to_test)
    decoded = msgpack_utils.msg_unpack(encoded)
    assert to_test == decoded
def test_msgpack_utils__msg_pack__will_pack_and_unpack_uuid_object():
    """
    Make sure the function can pack a decimal object.
    """
    to_test = {
        'regular_key': 'This is a regular obj...',
        'uuid_key': uuid4(),
    }

    encoded = msgpack_utils.msg_pack(to_test)
    decoded = msgpack_utils.msg_unpack(encoded)
    assert to_test == decoded
    def _decode_message(self, binary_message):
        """
        this method is needed to take the binary message from the inbound
        socket and convert it into a payload for the service framework to
        then handle.
        """
        opt_args = self.model.get('optional_creation_arguments', {})
        topic = opt_args.get('topic', '')
        topic_bytes = msg_pack(topic)

        if topic:
            msg_only = binary_message[len(topic_bytes):]
            return msg_unpack(msg_only)

        return msg_unpack(binary_message)
def get_subscriber_socket(address, context, tag='', is_binder=False):
    """
    address::str ex. "127.0.0.1:5001"
    context::zmq.Context()
    tag::str Tag to filter the subscriber by...
    is_x_sub::bool A flag to determine if XSUB or SUB should be used.
    """
    LOG.debug('Creating subscriber socket for address %s', address)
    socket = context.socket(zmq.SUB)

    if tag:
        socket.setsockopt(zmq.SUBSCRIBE, msg_pack(tag))
    else:
        socket.setsockopt_string(zmq.SUBSCRIBE, '')

    if is_binder:
        port = address.split(':')[-1]
        uri = 'tcp://*:%s' % port
        socket.bind(uri)
    else:
        uri = 'tcp://%s' % address
        socket.connect(uri)

    return socket