コード例 #1
0
    def test_server_can_bind_on_random_port(self):
        server = Server(port=None)

        assert server.port == None

        listener = server.pull()

        assert isinstance(server.port, int)
コード例 #2
0
    def test_server_can_bind_on_random_port(self):
        server = Server(port=None)

        assert server.port == None

        listener = server.pull()

        assert isinstance(server.port, int)
コード例 #3
0
ファイル: pubsub.py プロジェクト: vegetablejuiceftw/sauron
def get_server(
        port: int,
        topics: List[str]) -> Dict[str, Callable[[BaseMessageType], None]]:
    # And assigns a callable to publish messages with the topics'
    srv = Server(port=port)

    mapping = {
        topic: srv.pub(topic=topic.encode('utf-8'), embed_topic=True)
        for topic in topics
    }
    return {
        k: (lambda packet: v(packet.json().encode('utf-8')))
        for k, v in mapping.items()
    }
コード例 #4
0
    def test_published_topic_is_not_included_into_message(self):
        pub = Server(port=7150).pub(topic=b'topic1')

        pub(b'topic1 msg')

        with pytest.raises(ValueError):
            pub(b'msg')
コード例 #5
0
def main():
    listen_for_push = Server(port=helpers.ports['task_manager']).pull()
    for msg in listen_for_push:
        obj = json.loads(msg.decode())
        if obj['@type'] == 'Measurement':
            test_conditions(obj)
        else:
            print("i don't know what to do with this message")
コード例 #6
0
ファイル: zmq_server.py プロジェクト: sytelus/airviz
class ZmqServer:
    def start(self, port):
        self._server = Server(port=port)
        self.pubs = {}

    def send(self, obj, topic):
        if not topic in self.pubs:
            self.pubs[topic] = self._server.pub(topic=topic, embed_topic=True)
        self.pubs[topic](obj)
コード例 #7
0
    def test_port_under_range(self):
        client = Client()
        with pytest.raises(ValueError):
           client.connect_local(port=1023)

        with pytest.raises(ValueError):
           client.disconnect_local(port=1023)

        with pytest.raises(ValueError):
            Server(port=1023)
コード例 #8
0
def pub_with_empty_topic():
    return Server(port=7896).pub(embed_topic=True)
コード例 #9
0
def pub_with_topic():
    return Server(port=7895).pub(topic=b'sh')
コード例 #10
0
def pub_with_embedded_topic():
    return Server(port=7894).pub(topic=b'sh', embed_topic=True)
コード例 #11
0
ファイル: test_reqrep.py プロジェクト: davinirjr/zeroless
def reply_gens():
    return Server(port=7892).reply()
コード例 #12
0
def pub():
    return Server(port=7893).pub()
コード例 #13
0
def listen_for_push():
    return Server(port=7891).pull()
コード例 #14
0
from zeroless import Server

# Binds the pair server to port 12345
# And assigns a callable and an iterable
# To both transmit and wait for incoming messages
pair, listen_for_pair = Server(port=12345).pair()

for id, msg in listen_for_pair:
    print(id, ' - ', msg)
    pair(msg)
コード例 #15
0
from flask_restful import Api, Resource, reqparse

from lib.accounts import authentication as auth
from lib.services import utils as services_util

import en_us
import utils

import json
import os

import traceback

from zeroless import (Server)

pub = Server(port=35893).pub()


class start(Resource):
    def post(self, client_id, service_id):
        request_token = request.headers.get('authorization')
        auth_status = auth.verify(client_id, request_token)
        if auth_status != 200:
            return auth_status

        service = utils.get_service(client_id, service_id)
        if service.count() == 0:
            return en_us.NOT_FOUND

        command = {
            "serviceid": service_id,
コード例 #16
0
ファイル: zmq_server.py プロジェクト: sytelus/airviz
 def start(self, port):
     self._server = Server(port=port)
     self.pubs = {}
コード例 #17
0
    def test_port_already_used(self):
        listen_for_push = Server(port=65000).pull()

        with pytest.raises(ValueError):
            Server(port=65000).pull()
コード例 #18
0
import logging

from time import sleep

from zeroless import (Server, log)

# Setup console logging
consoleHandler = logging.StreamHandler()
log.setLevel(logging.DEBUG)
log.addHandler(consoleHandler)

# Binds the publisher server to port 12345
# And assigns a callable to publish messages with the topic 'sh'
pub = Server(port=12345).pub(topic=b'sh', embed_topic=True)

# Gives publisher some time to get initial subscriptions
sleep(1)

for msg in [b"Msg1", b"Msg2", b"Msg3"]:
    pub(msg)
コード例 #19
0
    def test_published_topic_is_not_bytes(self):
        Server(port=7099).pub(topic=b'topic1')

        with pytest.raises(TypeError):
            Server(port=7100).pub(topic=u'topic1')
コード例 #20
0
import logging

from zeroless import (Server, log)

# Setup console logging
consoleHandler = logging.StreamHandler()
log.setLevel(logging.DEBUG)
log.addHandler(consoleHandler)

# Binds the reply server to port 12345
# And assigns a callable and an iterable
# To both transmit and wait for incoming messages
reply, listen_for_request = Server(port=12345).reply()

for msg in listen_for_request:
    print(msg)
    reply(msg)
コード例 #21
0
from time import sleep, time

from zeroless import (Server, Client)

# Binds the publisher server to port 12345
# And assigns a callable to publish messages with the topic 'sh'
pub = Server(port=12345).pub(topic=b'topic_name', embed_topic=True)

# Gives publisher some time to get initial subscriptions
while True:
    pub(b"%f" % time())
    sleep(0.2)
コード例 #22
0
    def test_server_port_property(self):
        port = 1050
        server = Server(port=port)

        assert server.port == port
コード例 #23
0
mqtt_port = int(environ['MQTT_PORT'])

zmq_client = Client()
zmq_client.connect_local(port=helpers.ports['device_manager'])
zmq_push = zmq_client.push()

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    client.subscribe("gateways/test")


def on_message(client, userdata, msg):
    zmq_push(msg.payload)


client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect(mqtt_broker_ip, mqtt_port, 60)

#Listen for gateways' MQTT messages
client.loop_start()

#Listen for DeviceManager ZMQ messages
listen_for_push = Server(port=helpers.ports['broker']).pull()
for msg in listen_for_push:
    print(msg.decode())
    client.publish("gateways/broker",msg.decode())

client.loop_stop()
コード例 #24
0
from zeroless import Server

from time import sleep

# Binds the publisher server to port 12345
# And assigns a callable to publish messages with no topic specified
pub = Server(port=12345).pub(embed_topic=True)

# Gives publisher some time to get initial subscriptions
sleep(1)

for id, msg in [(b"1", b"Msg1"), (b"2", b"Msg2"), (b"3", b"Msg3")]:
    pub(id, msg)
コード例 #25
0
ファイル: test_pair.py プロジェクト: davinirjr/zeroless
def listen_for_pair():
    _, listen = Server(port=7890).pair()
    return listen
コード例 #26
0
ファイル: pushPullServer.py プロジェクト: davinirjr/zeroless
import logging

from zeroless import (Server, log)

# Setup console logging
consoleHandler = logging.StreamHandler()
log.setLevel(logging.DEBUG)
log.addHandler(consoleHandler)

# Binds the pull server to port 12345
# And assigns an iterable to wait for incoming messages
listen_for_push = Server(port=12345).pull()

for msg in listen_for_push:
    print(msg)
コード例 #27
0
def main():
    listen_for_push = Server(port=helpers.ports['device_manager']).pull()
    for msg in listen_for_push:
        obj = json.loads(msg.decode())
        #Measurement
        if obj['@type'] == 'Measurement':
            if verify('devices', obj['dev:wasMeasuredBy']):
                create('measurements', obj)
                push_to_task(msg)
            else:
                notify_unknown_object('Device', obj['dev:wasMeasuredBy'])
        #Device
        elif obj['@type'] == 'Device':
            if verify('platforms', obj['dev:hasPlatform']):
                create('devices', obj)
            else:
                notify_unknown_object('Platform', obj['dev:hasPlatform'])
        #Platform
        elif obj['@type'] == 'Platform':
            if verify('continuous_sensors', obj['dev:hasSensor']) or\
                    verify('discrete_sensors', obj['dev:hasSensor']):
                if verify('continuous_actuators', obj['dev:hasActuator']) or\
                        verify('discrete_actuators', obj['dev:hasActuator']):
                    create('platforms', obj)
                else:
                    notify_unknown_object('Actuator', obj['dev:hasActuator'])
            else:
                notify_unknown_object('Sensor', obj['dev:hasSensor'])
        #ContinuousSensor
        elif obj['@type'] == 'ContinuousSensor':
            if verify('units', obj['sense:canMeasure']):
                create('continuous_sensors', obj)
            else:
                notify_unknown_object('Unit', obj['sense:canMeasure'])
        #DiscreteSensor
        elif obj['@type'] == 'DiscreteSensor':
            if verify('variables', obj['sense:canMeasure']):
                create('discrete_sensors', obj)
            else:
                notify_unknown_object('Variable', obj['sense:canMeasure'])
        #ContinuousActuator
        elif obj['@type'] == 'ContinuousActuator':
            if verify('variables', obj['actuator:increases']):
                create('continuous_actuators', obj)
            else:
                notify_unknown_object('Variable', obj['actuator:increases'])
        #DiscreteActuator
        elif obj['@type'] == 'DiscreteActuator':
            if verify('variables', obj['actuator:changeState']):
                create('discrete_actuators', obj)
            else:
                notify_unknown_object('Variable', obj['actuator:changeState'])
        #Unit
        elif obj['@type'] == 'Unit':
            if verify('variables', obj['sense:unitOf']):
                create('units', obj)
            else:
                notify_unknown_object('Variable', obj['sense:unitOf'])
        #Variable
        elif obj['@type'] == 'Variable':
            create('variables', obj)