Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package client;
- import io.grpc.ManagedChannel;
- import io.grpc.ManagedChannelBuilder;
- import proto.UserOuterClass.CreateUserRequest;
- import proto.UserOuterClass.CreateUserResponse;
- import proto.UserOuterClass.GetUserRequest;
- import proto.UserOuterClass.GetUserResponse;
- import proto.UserOuterClass.ListUserRequest;
- import proto.UserOuterClass.ListUserResponse;
- import proto.UserOuterClass.User;
- import proto.UserServiceGrpc;
- public class UserClient {
- public static void main(String[] args) {
- UserClient main = new UserClient();
- ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 50051).usePlaintext().build();
- UserServiceGrpc.UserServiceBlockingStub userClient = UserServiceGrpc.newBlockingStub(channel);
- // CREATE USER
- User user = User.newBuilder().setName("luiz").setEmail("teste@teste.com").build();
- CreateUserResponse createUserResponse = userClient
- .createUser(CreateUserRequest.newBuilder().setUser(user).build());
- System.out.println(createUserResponse.toString());
- int userId = createUserResponse.getUser().getId();
- // Get USER
- GetUserResponse getUserResponse = userClient.getUser(GetUserRequest.newBuilder().setUserId(userId).build());
- System.out.println(getUserResponse.getUser());
- // DELETE USER
- //DeleteUserResponse deleteUserResponse = userClient
- // .deleteUser(DeleteUserRequest.newBuilder().setUserId(userId).build());
- //System.out.println(deleteUserResponse.getUserId());
- // LIST USERS
- ListUserResponse listUserResponse = userClient.listUser(ListUserRequest.newBuilder().build());
- System.out.println(listUserResponse.getUserList());
- }
- }
Add Comment
Please, Sign In to add comment