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

Method main

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

Source from the content-addressed store, hash-verified

13 private static final String TASK_QUEUE_NAME = "task_queue";
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(TASK_QUEUE_NAME).quorum().queue().declare();
20 // Un-comment the following line to declare a Classic Queue
21 // Comment the previous queue declaration, if you un-comment below
22 // management.queue(TASK_QUEUE_NAME).classic().queue().declare();
23 }
24 try (Publisher publisher = connection.publisherBuilder().queue(TASK_QUEUE_NAME).build()) {
25 String message = String.join(" ", argv);
26 Message msg = publisher.message(message.getBytes(StandardCharsets.UTF_8)).durable(true);
27 CountDownLatch confirmed = new CountDownLatch(1);
28 publisher.publish(msg, ctx -> {
29 if (ctx.status() == Publisher.Status.ACCEPTED) {
30 confirmed.countDown();
31 }
32 });
33 if (!confirmed.await(30, TimeUnit.SECONDS)) {
34 throw new IllegalStateException("Publish was not confirmed in time");
35 }
36 System.out.println(" [x] Sent '" + message + "'");
37 }
38 } finally {
39 environment.close();
40 }
41 }
42}

Callers

nothing calls this directly

Calls 3

newEnvironmentMethod · 0.95
queueMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected