Exemple #1
0
def event_subscriber(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.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()
def subcribe_to_event_store(queue_name, client_id, kube_add):
    subscriber = Subscriber(kube_add)
    cancel_token = ListenerCancellationToken()
    sub_req = SubscribeRequest(
        channel="MyTestChannelNameStore",
        client_id=str(randint(9, 19999)),
        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()
Exemple #3
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")
Exemple #4
0

if __name__ == "__main__":
    lett_dig = string.ascii_letters + string.digits
    channel = ''.join(random.choice(lett_dig) for i in range(5))
    group_name = 'group1'
    cancel_token = ListenerCancellationToken()
    try:

        subscriber_a = Subscriber("localhost:50000")
        subscribe_request_a = create_subscribe_request(
            SubscribeType.EventsStore,
            'python-sdk-cookbook-pubsub-events-store-load-balance-receiver-a',
            EventsStoreType.StartFromFirst, 0, channel, group_name)
        subscriber_a.subscribe_to_events(subscribe_request_a,
                                         handle_incoming_events_receiver_a,
                                         handle_incoming_error, cancel_token)

        subscriber_b = Subscriber("localhost:50000")
        subscribe_request_b = create_subscribe_request(
            SubscribeType.EventsStore,
            'python-sdk-cookbook-pubsub-events-store-load-balance-receiver-b',
            EventsStoreType.StartFromFirst, 0, channel, group_name)
        subscriber_b.subscribe_to_events(subscribe_request_b,
                                         handle_incoming_events_receiver_b,
                                         handle_incoming_error, cancel_token)

        subscriber_c = Subscriber("localhost:50000")
        subscribe_request_c = create_subscribe_request(
            SubscribeType.EventsStore,
            'python-sdk-cookbook-pubsub-events-store-load-balance-v',