def create_subscribe_request(subscribe_type=SubscribeType.Events,
                             events_store_type=EventsStoreType.Undefined,
                             events_store_type_value=0):
    return SubscribeRequest(channel="MyTestChannelName",
                            client_id=str(randint(9, 19999)),
                            events_store_type=events_store_type,
                            events_store_type_value=events_store_type_value,
                            group="",
                            subscribe_type=subscribe_type)
Exemplo n.º 2
0
def create_subscribe_request(subscribe_type=SubscribeType.Events,
                             client_id="",
                             events_store_type=EventsStoreType.Undefined,
                             events_store_type_value=0,
                             channel_name='events-store'):
    return SubscribeRequest(channel=channel_name,
                            client_id=client_id,
                            events_store_type=events_store_type,
                            events_store_type_value=events_store_type_value,
                            group="",
                            subscribe_type=subscribe_type)
Exemplo n.º 3
0
def subscribe_to_requests(channel_name, p_client_id, kube_add):
    responder = Responder(kube_add)
    cancel_token = ListenerCancellationToken()
    sub_req = SubscribeRequest(channel=channel_name,
                               client_id=p_client_id,
                               events_store_type=EventsStoreType.Undefined,
                               events_store_type_value=0,
                               group="",
                               subscribe_type=SubscribeType.Queries)
    responder.subscribe_to_requests(sub_req, handle_incoming_request,
                                    handle_incoming_error, cancel_token)
    print("sub for 10 seconds")
    time.sleep(10.0)
    print("Canceled token")
    cancel_token.cancel()
Exemplo n.º 4
0
def event_subscriber(queue_name, client_id, kube_add):
    subscriber = Subscriber(kube_add)
    cancel_token = ListenerCancellationToken()
    sub_req = SubscribeRequest(channel="MyTestChannelName",
                               client_id=str(randint(9, 19999)),
                               events_store_type=EventsStoreType.Undefined,
                               events_store_type_value=0,
                               group="",
                               subscribe_type=SubscribeType.Events)
    subscriber.subscribe_to_events(sub_req, handle_incoming_events,
                                   handle_incoming_error, cancel_token)
    print("sub for 2 seconds")
    time.sleep(2.0)
    print("Canceled token")
    cancel_token.cancel()
Exemplo n.º 5
0
def subcribe_to_event_store(channel_name, p_client_id, kube_add):
    subscriber = Subscriber(kube_add)
    cancel_token = ListenerCancellationToken()
    sub_req = SubscribeRequest(
        channel=channel_name,
        client_id=p_client_id,
        events_store_type=EventsStoreType.StartFromFirst,
        events_store_type_value=0,
        group="",
        subscribe_type=SubscribeType.EventsStore)
    subscriber.subscribe_to_events(sub_req, handle_incoming_events,
                                   handle_incoming_error, cancel_token)
    print("sub for 2 seconds")
    time.sleep(2.0)
    print("Canceled token")
    cancel_token.cancel()
Exemplo n.º 6
0
def handle_incoming_events(event):
    if event:
        print(
            "Subscriber Received Event: Metadata:'%s', Channel:'%s', Body:'%s tags:%s'"
            % (event.metadata, event.channel, event.body, event.tags))


def handle_incoming_error(error_msg):
    print("received error:%s'" % (error_msg))


if __name__ == "__main__":
    print("Subscribing to event on channel example")
    cancel_token = ListenerCancellationToken()

    # Subscribe to events without store
    subscriber = Subscriber("localhost:50000")
    subscribe_request = SubscribeRequest(
        channel="MyTestChannelName",
        client_id="hello-world-subscriber",
        events_store_type=EventsStoreType.Undefined,
        events_store_type_value=0,
        group="",
        subscribe_type=SubscribeType.Events)
    subscriber.subscribe_to_events(subscribe_request, handle_incoming_events,
                                   handle_incoming_error, cancel_token)

    input("Press 'Enter' to stop Listen...\n")
    cancel_token.cancel()
    input("Press 'Enter' to stop the application...\n")

def handle_incoming_error(error_msg):
    print("received error:%s'" % (error_msg))


if __name__ == "__main__":
    cancel_token = ListenerCancellationToken()
    receiver = Responder("localhost:50000",
                         encryptionHeader=jwt.encode({},
                                                     algorithm="HS256",
                                                     key="some-key"))

    subscribe_request = SubscribeRequest(
        channel="testing_Command_channel",
        client_id='hello-world-sender',
        events_store_type=SubscribeType.SubscribeTypeUndefined,
        events_store_type_value=0,
        group="",
        subscribe_type=SubscribeType.Commands)
    try:
        receiver.subscribe_to_requests(subscribe_request,
                                       handle_incoming_request,
                                       handle_incoming_error, cancel_token)

        input("Press 'Enter' to stop Listen...\n")
        cancel_token.cancel()
        input("Press 'Enter' to stop the application...\n")
    except Exception as err:
        print("'error sending:'%s'" % (err))