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

Method main

java-amqp/src/main/java/Send.java:15–38  ·  view source on GitHub ↗
(String[] argv)

Source from the content-addressed store, hash-verified

13 private static final String QUEUE_NAME = "hello";
14
15 public static void main(String[] argv) throws Exception {
16 Environment environment = TutorialSupport.newEnvironment();
17 try (Connection connection = environment.connectionBuilder().uri(TutorialSupport.BROKER_URI).build()) {
18 try (Management management = connection.management()) {
19 management.queue().name(QUEUE_NAME).quorum().queue().declare();
20 }
21 try (Publisher publisher = connection.publisherBuilder().queue(QUEUE_NAME).build()) {
22 String message = "Hello World!";
23 Message msg = publisher.message(message.getBytes(StandardCharsets.UTF_8));
24 CountDownLatch confirmed = new CountDownLatch(1);
25 publisher.publish(msg, ctx -> {
26 if (ctx.status() == Publisher.Status.ACCEPTED) {
27 confirmed.countDown();
28 }
29 });
30 if (!confirmed.await(30, TimeUnit.SECONDS)) {
31 throw new IllegalStateException("Publish was not confirmed in time");
32 }
33 System.out.println(" [x] Sent '" + message + "'");
34 }
35 } finally {
36 environment.close();
37 }
38 }
39}

Callers

nothing calls this directly

Calls 3

newEnvironmentMethod · 0.95
queueMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected