示例#1
0
def get_streams():
    streams = ProtonPack.list_streams()
    return make_response(
        json_dumps({
            "status": "ok",
            "streams": list(streams)
        }), 200)
示例#2
0
def get_stream_consumer_groups(stream):
    groups = ProtonPack.list_consumer_groups(stream)
    return make_response(
        json_dumps({
            "status": "ok",
            "stream": stream,
            "groups": [group.to_dict() for group in groups]
        }), 200)
示例#3
0
def get_stream_subscribers(stream):
    subscribers = SubscriberManager.get_subscribers_for(stream)
    return make_response(
        json_dumps({
            "status":
            "ok",
            "stream":
            stream,
            "subscribers":
            [subscriber.to_dict() for subscriber in subscribers]
        }), 200)
示例#4
0
def put_stream_consumer_group(stream):
    data = request.get_json(force=True)
    group_name = data.get("group_name")
    group = ProtonPack.create_consumer_group(stream, group_name)
    return make_response(
        json_dumps({
            "status": "ok",
            "stream": stream,
            "group_name": group_name,
            "created": group
        }), 200)
示例#5
0
def put_stream_subscriber(stream):
    data = request.get_json(force=True)
    subscriber = Subscriber.from_dict(data)
    created = SubscriberManager.put_subscriber(subscriber)
    return make_response(
        json_dumps({
            "status": "ok",
            "stream": stream,
            "subscriber": subscriber.subscriber_name,
            "created": created
        }), 200)
示例#6
0
def delete_stream_subscriber(stream, subscriber_name):
    ok = False
    subscribers = SubscriberManager.get_subscribers_for(stream)
    for subscriber in subscribers:
        if subscriber.subscriber_name == subscriber_name:
            ok = SubscriberManager.del_subscriber(subscriber)
            break
    return make_response(
        json_dumps({
            "status": "ok",
            "stream": stream,
            "subscriber": subscriber_name,
            "deleted": ok
        }), 200)
示例#7
0
def get_stream_info(stream):
    if request.method == "GET":
        info = ProtonPack.stream_info(stream)
        return make_response(
            json_dumps({
                "status": "ok",
                "stream": stream,
                "info": info
            }), 200)
    elif request.method == "POST":
        raw = request.get_json(force=True)
        if isinstance(raw, collections.Mapping):
            event = Event.from_dict(raw)
            evt_id = ProtonPack.send_event(stream, event)
            raw["event_id"] = evt_id
            app.logger.debug({"action": "event_posted", "event": raw})
            return make_response(
                json_dumps({
                    "status": "ok",
                    "stream": stream,
                    "events": [evt_id]
                }), 200)
        else:
            evt_ids = []
            for evt in raw:
                event = Event.from_dict(evt)
                evt_id = ProtonPack.send_event(stream, event)
                evt["event_id"] = evt_id
                evt_ids.append(evt_id)
                app.logger.debug({"action": "event_posted", "event": evt})
            return make_response(
                json_dumps({
                    "status": "ok",
                    "stream": stream,
                    "events": evt_ids
                }), 200)
示例#8
0
def root_handler():
    if request.method == "POST":
        data = request.get_json(force=True)
        app.logger.info(json_dumps(data))
    return make_response(json_dumps({"status": "ok"}), 200)
示例#9
0
 def queue_for_subscriber_error(self, subscriber, evt):
     client = self.redis_connect()
     return client.xadd(f"janitorial::{self.stream_name}", {
         "subscriber": subscriber,
         "event": json_dumps(evt)
     })