static void publishMessagesInBatch() throws Exception {
        try (Connection connection = createConnection()) {
            Channel ch = connection.createChannel();

            String queue = UUID.randomUUID().toString();
            ch.queueDeclare(queue, false, false, true, null);

            ch.confirmSelect();

            int batchSize = 100;
            int outstandingMessageCount = 0;

            long start = System.nanoTime();
            for (int i = 0; i < MESSAGE_COUNT; i++) {
                String body = String.valueOf(i);
                ch.basicPublish("", queue, null, body.getBytes());
                outstandingMessageCount++;

                if (outstandingMessageCount == batchSize) {
                    ch.waitForConfirmsOrDie(5_000);
                    outstandingMessageCount = 0;
                }
            }

            if (outstandingMessageCount > 0) {
                ch.waitForConfirmsOrDie(5_000);
            }
            long end = System.nanoTime();
            System.out.format("Published %,d messages in batch in %,d ms%n", MESSAGE_COUNT, Duration.ofNanos(end - start).toMillis());
        }
    }
@Test
    @DisplayName("publish messages in batch")
    void publishMessagesInBatch() throws Exception {
        Channel ch = connection.createChannel();
        ch.confirmSelect();
        int batchSize = 100;
        int outstandingMessageCount = 0;
        for (int i = 0; i < messageCount; i++) {
            String body = String.valueOf(i);
            ch.basicPublish("", queue, null, body.getBytes());
            outstandingMessageCount++;

            if (outstandingMessageCount == batchSize) {
                ch.waitForConfirmsOrDie(5_000);
                outstandingMessageCount = 0;
            }
            meter.mark();
        }

        if (outstandingMessageCount > 0) {
            ch.waitForConfirmsOrDie(5_000);
        }

        ch.close();

        CountDownLatch latch = new CountDownLatch(messageCount);
        ch = connection.createChannel();
        ch.basicConsume(queue, true, ((consumerTag, message) -> latch.countDown()), consumerTag -> {
        });

        assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
    }