-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallService.java
More file actions
67 lines (59 loc) · 2.06 KB
/
CallService.java
File metadata and controls
67 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package examples;
import build.skir.service.ServiceClient;
import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import skirout.service.AddUserRequest;
import skirout.service.GetUserRequest;
import skirout.service.GetUserResponse;
import skirout.service.Methods;
import skirout.user.Constants;
import skirout.user.SubscriptionStatus;
import skirout.user.User;
/**
* Sends RPCs to a Skir service. See StartService.java for how to start one.
*
* <p>Run with: ./gradlew run -PmainClass=examples.CallService
*
* <p>Make sure the service is running first (using StartService).
*/
public class CallService {
public static void main(String[] args) throws Exception {
final ServiceClient serviceClient = new ServiceClient("http://localhost:8787/myapi");
System.out.println();
System.out.println("About to add 2 users: John Doe and Tarzan");
// Add John Doe
serviceClient.invokeRemoteBlocking(
Methods.ADD_USER,
AddUserRequest.builder()
.setUser(
User.builder()
.setName("John Doe")
.setPets(List.of())
.setQuote("")
.setSubscriptionStatus(SubscriptionStatus.UNKNOWN)
.setUserId(42)
.build())
.build(),
Map.of(),
Duration.ofSeconds(30));
// Add Tarzan with custom headers
final Map<String, List<String>> customHeaders = new HashMap<>();
customHeaders.put("X-Foo", List.of("hi"));
serviceClient.invokeRemoteBlocking(
Methods.ADD_USER,
AddUserRequest.builder().setUser(Constants.TARZAN).build(),
customHeaders,
Duration.ofSeconds(30));
System.out.println("Done");
// Get user by ID
final GetUserResponse foundUserResponse =
serviceClient.invokeRemoteBlocking(
Methods.GET_USER,
GetUserRequest.builder().setUserId(123).build(),
Map.of(),
Duration.ofSeconds(30));
System.out.println("Found user: " + foundUserResponse.user());
}
}