コード例 #1
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()
コード例 #2
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()
コード例 #3
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()
コード例 #4
0
    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 with store
    subscriber = Subscriber("localhost:50000")
    subscribe_request = create_subscribe_request(SubscribeType.EventsStore, EventsStoreType.StartAtSequence, 2)
    subscriber.subscribe_to_events(subscribe_request, handle_incoming_events,handle_incoming_error,cancel_token)

    # Subscribe to events without store
    subscriber = Subscriber("localhost:50000")
    subscribe_request = create_subscribe_request(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")