Q: Get message ID from producer.send(message) How can I get MessageId after sending the message but without consuming the message?
I have this method which send the message to queue
public void sentMessage(JmsTemplate jmsTemplate, String queueName, String message, String uuid) {
        jmsTemplate.convertAndSend(queueName, message,
                new MessagePostProcessor() {
                    @Override
                    public Message postProcessMessage(Message message) throws JMSException {
                        message.setStringProperty("uuid", uuid);
                        log.info("CorId:{}", message.getJMSCorrelationID());
                        return message;
                    }
                });
    }

but I needed to find out the id after sending the message, but without consuming the message and I wrote this method:
public ApplicationRunner sentMessage(JmsTemplate jmsTemplate, String queueName, String message, String uuid) {
        return args -> {
            final AtomicReference<Message> msg = new AtomicReference<>();
            jmsTemplate.convertAndSend(queueName, message, m -> {
                msg.set(m);
                return m;
            });
            String message1 = msg.get().getJMSCorrelationID();
            log.info("CorId:{}", message1);
        };
    }

how to rewrite a method so that you can call it in another class and get messageId?
I write this
public String sentMessage(JmsTemplate jmsTemplate, String queueName, String message, String uuid) throws JMSException {
        return t -> {
            final AtomicReference<Message> msg = new AtomicReference<>();
            jmsTemplate.convertAndSend(queueName, message, m -> {
                msg.set(m);
                return m;
            });
            return msg.get().getJMSCorrelationID();
        };
    }

but get error: target type of lambda conversion must be an interface

A: Why are you using a lambda there? What is t? A String is not a Consumer<?>.
public String sentMessage(JmsTemplate jmsTemplate, String queueName, String message, String uuid)
        throws JMSException {

    final AtomicReference<Message> msg = new AtomicReference<>();
    jmsTemplate.convertAndSend(queueName, message, m -> {
        msg.set(m);
        return m;
    });
    return msg.get().getJMSCorrelationID();
}

is all you need.
