Class MessageTemplate

java.lang.Object
com.codename1.backend.messaging.MessageTemplate

public final class MessageTemplate extends Object

Sends messages through the server's transport: what an application injects to publish, as it would Spring's KafkaTemplate or RabbitTemplate.

@Service
public class Orders {
    private final MessageTemplate messages;
    public Orders(MessageTemplate messages) { this.messages = messages; }

    @Transactional
    public void place(Order order) {
        repository.save(order);
        messages.send("orders.placed", order);
    }
}

A payload is sent as it is when it is a byte[], as UTF-8 when it is a String, and otherwise as JSON written by the codec the build generated for its type.

Inside a database transaction a send happens only if the transaction commits. The db: transport writes the message in the transaction itself; a broker transport writes it to an outbox table in the transaction and relays it after the commit, so a rollback sends nothing and a crash between the commit and the relay sends it when the server comes back. memory: holds the message until the commit.