MCPcopy Index your code
hub / github.com/rabbitmq/rabbitmq-tutorials / main

Method main

java-amqp/src/main/java/RPCServer.java:22–55  ·  view source on GitHub ↗
(String[] argv)

Source from the content-addressed store, hash-verified

20 }
21
22 public static void main(String[] argv) throws Exception {
23 Environment environment = TutorialSupport.newEnvironment();
24 Connection connection = environment.connectionBuilder().uri(TutorialSupport.BROKER_URI).build();
25 try (Management management = connection.management()) {
26 management.queue().name(RPC_QUEUE_NAME).quorum().queue().declare();
27 management.queuePurge(RPC_QUEUE_NAME);
28 }
29
30 System.out.println(" [x] Awaiting RPC requests");
31
32 Responder responder = connection.responderBuilder()
33 .requestQueue(RPC_QUEUE_NAME)
34 .handler((ctx, req) -> {
35 String response = "";
36 try {
37 String message = new String(req.body(), StandardCharsets.UTF_8);
38 int n = Integer.parseInt(message);
39 System.out.println(" [.] fib(" + message + ")");
40 response += fib(n);
41 } catch (RuntimeException e) {
42 System.out.println(" [.] " + e);
43 }
44 return ctx.message(response.getBytes(StandardCharsets.UTF_8));
45 })
46 .build();
47
48 Runtime.getRuntime().addShutdownHook(new Thread(() -> {
49 responder.close();
50 connection.close();
51 environment.close();
52 }));
53
54 Thread.sleep(Long.MAX_VALUE);
55 }
56}

Callers

nothing calls this directly

Calls 4

newEnvironmentMethod · 0.95
fibMethod · 0.95
queueMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected