Exemplo n.º 1
0
def run():
    channel = grpc.insecure_channel(
        'localhost:50051')  #create a channel to our server
    try:
        grpc.channel_ready_future(channel).result(
            timeout=10)  #client waits for timeout
    except grpc.FutureTimeoutError:
        sys.exit('Error connecting to server')
    else:
        stub = users_service.UsersStub(
            channel
        )  #else create a BertSqquadStub object and pass channel as arg
        metadata = [('ip', '127.0.0.1')]
        response = stub.CreateUser(
            users_messages.CreateUserRequest(username='******'),
            metadata=metadata,
        )
        if response:
            print("User created:", response.user.username)
        request = users_messages.GetUsersRequest(  #request is of repeated type, so it is a list
            user=[
                users_messages.User(
                    username="******",
                    user_id=1),  #repeated User in GetUsersRequest message
                users_messages.User(username="******", user_id=1)
            ])
        response = stub.GetUsers(
            request)  #result of GetUsers is a stream, so iterate over it
        for resp in response:
            print(resp)
Exemplo n.º 2
0
def run():
    channel = grpc.insecure_channel('localhost:50051')
    try:
        grpc.channel_ready_future(channel).result(timeout=10)
    except grpc.FutureTimeoutError:
        sys.exit('Error connecting to server')
    else:
        stub = users_service.UsersStub(channel)

        metadata = [('ip', '127.0.0.1')]
        response = stub.CreateUser(
            users_messages.CreateUserRequest(username='******'),
            metadata=metadata,
        )
        if response:
            print("User created:", response.user.username)

        request = users_messages.GetUsersRequest(user=[
            users_messages.User(username="******", user_id=1),
            users_messages.User(username="******", user_id=1),
            users_messages.User(username="******", user_id=1),
        ])
        response = stub.GetUsers(request)
        for resp in response:
            print(resp)
Exemplo n.º 3
0
def run():
    users = ServiceClient(users_service, 'UsersStub', 'localhost', 50051)
    # Insert example metadata
    metadata = [('ip', '127.0.0.1')]
    response = users.CreateUser(
        users_messages.CreateUserRequest(username='******'), metadata=metadata)
    if response:
        print("User created:", response.user.username)
    request = users_messages.GetUsersRequest(user=[
        users_messages.User(username="******", user_id=1),
        users_messages.User(username="******", user_id=1)
    ])
    response = users.GetUsers(request)
    for resp in response:
        print(resp)
Exemplo n.º 4
0
 def run(self):
     global count
     while True:
         channel = grpc.insecure_channel('localhost:50051')
         try:
             grpc.channel_ready_future(channel).result(timeout=10)
         except grpc.FutureTimeoutError:
             sys.exit('Error connecting to server')
         else:
             stub = users_service.UsersStub(channel)
             metadata = [('ip', '127.0.0.1')]
             # replace with file big file
             data = ''.join(secrets.choice(string.ascii_uppercase + string.digits)
                            for i in range(1024*1024))
             response = stub.CreateUser(
                 users_messages.CreateUserRequest(username=data),
                 metadata=metadata,
             )
             if response:
                 count += 1
                 print(str(count))