(String[] argv)
| 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 | } |
nothing calls this directly
no test coverage detected