To send an SMS from Quarkus, declare a REST client interface with @RegisterRestClient, put the API key in a @ClientHeaderParam, and wrap the call in a service that uses @Retry and @Timeout from SmallRye Fault Tolerance. Pass one Idempotency-Key per message so each retry is the same send, not a new one.

We make Ready, so the example uses the Ready REST API and only the request shape we document. If you're on Spring instead, see our Spring Boot SMS guide. The code here is Java, and a Kotlin version of the pieces that differ follows.

Dependencies and configuration

Add the REST client with Jackson and the fault tolerance extension:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-rest-client-jackson</artifactId>
</dependency>
<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-smallrye-fault-tolerance</artifactId>
</dependency>

Then in application.properties:

quarkus.rest-client.ready.url=https://api.tryready.com
quarkus.rest-client.ready.connect-timeout=5000
quarkus.rest-client.ready.read-timeout=12000
ready.api-key=${READY_API_KEY}

The client-level timeouts are a floor. @Timeout on the service sets the budget for a whole attempt, and the retry decides what happens next. Reading the key from READY_API_KEY keeps it out of the repository, and a missing variable shows up as a configuration error instead of a silent empty header.

The REST client interface

import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import com.fasterxml.jackson.annotation.JsonProperty;

@RegisterRestClient(configKey = "ready")
@Path("/v1/messages")
@ClientHeaderParam(name = "X-API-Key", value = "${ready.api-key}")
public interface ReadyClient {

    record SendRequest(
        String to,
        String body,
        @JsonProperty("consent_attested") boolean consentAttested) {}

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    Response send(@HeaderParam("Idempotency-Key") String key, SendRequest request);
}

to is E.164, and a 10-digit US number is treated as +1. Set consentAttested to true only when the recipient agreed to texts, and read the value from your own consent data rather than hard-coding it in real code. The ${ready.api-key} expression is resolved from configuration each time the header is built.

The service with fault tolerance

The REST client throws a WebApplicationException for a 4xx or 5xx answer. The service turns that into two kinds of failure: one worth retrying and one that isn't.

import io.smallrye.faulttolerance.api.ExponentialBackoff;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.WebApplicationException;
import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.faulttolerance.Timeout;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import java.time.temporal.ChronoUnit;

@ApplicationScoped
public class SmsService {

    public static class RetryableException extends RuntimeException {
        public RetryableException(String m) { super(m); }
    }
    public static class ParkedException extends RuntimeException {
        public ParkedException(String m) { super(m); }
    }

    @Inject @RestClient ReadyClient client;

    @Retry(maxRetries = 4, delay = 500, jitter = 200,
           retryOn = RetryableException.class,
           abortOn = ParkedException.class)
    @ExponentialBackoff(factor = 2, maxDelay = 10, maxDelayUnit = ChronoUnit.SECONDS)
    @Timeout(value = 15, unit = ChronoUnit.SECONDS)
    public void send(String to, String body, String key) {
        try (var res = client.send(key, new ReadyClient.SendRequest(to, body, true))) {
            // 2xx falls through
        } catch (WebApplicationException e) {
            var status = e.getResponse().getStatus();
            var text = e.getResponse().hasEntity()
                ? e.getResponse().readEntity(String.class) : "";
            if (status == 429 || (status >= 500 && status != 503)
                    || (status == 409 && text.contains("idempotency_in_progress"))) {
                throw new RetryableException("status " + status);
            }
            throw new ParkedException("status " + status + ": " + text);
        }
    }
}

Three things matter here:

  1. The key is a parameter. @Retry re-invokes the method with the same arguments, so the same Idempotency-Key goes out on every attempt. Create the UUID once, where the business event happens, not inside this method.
  2. @Timeout runs per attempt when it sits beside @Retry, so a slow attempt is cut off and then retried instead of eating the whole budget.
  3. abortOn stops the loop for anything you've decided isn't transient.

Calling it from a resource:

@Path("/orders")
public class OrderResource {
    @Inject SmsService sms;

    @POST @Path("/{id}/shipped")
    public void shipped(@PathParam("id") String id) {
        sms.send("+12125550199", "Your order #" + id + " has shipped.",
                 java.util.UUID.randomUUID().toString());
    }
}

What each status should do

ResponseMeaningBehaviour
2xxAcceptedReturn
429Slow downRetryableException, same key
500, 502, 504Server troubleRetryableException, same key
503Not sentPark it, resend with a new key
409 idempotency_in_progressFirst attempt still runningRetryableException, same key
409 QUIET_HOURS_BLOCKA time rulePark it, resend once the window opens
Other 4xxBad number, opted-out contact, validationParkedException

A 409 QUIET_HOURS_BLOCK isn't a fault, so retrying it in 500 milliseconds can't help. An API text is held only if the window opens within a few hours. Otherwise it isn't sent, and you send it again once the window opens. Our retries and failure handling guide covers the full table.

The Kotlin version

The interface and service port almost line for line. The request body is a data class:

data class SendRequest(
    val to: String,
    val body: String,
    @get:JsonProperty("consent_attested") val consentAttested: Boolean,
)

Use @get:JsonProperty so Jackson sees the annotation on the getter. Make the service class open, or use the all-open plugin that Quarkus Kotlin projects configure, because interceptors like @Retry need a non-final class to subclass.

Sending from a queue instead of a request

Fault tolerance annotations are good for short bursts of retries inside a process. If the text must survive a restart, send the message through a queue and keep the key on the queued item. Our queue design guide explains why.

FAQ

Does @Retry on a POST risk a duplicate text?

Not with the same Idempotency-Key on every attempt. A repeated key means the request isn't sent twice, which is what makes the retry after a timeout safe.

Should I use the reactive client?

If your resource returns Uni, yes: the same interface works with Uni<Response>, and @Retry supports asynchronous methods. The status handling stays the same.

How do I test it?

Use WireMock through the quarkus-test-wiremock extension, return a 500 and then a 200, and assert both requests carried the same key. Our mocking guide shows the idea in another stack.

The short version

An interface for the call, a service for the policy, one key per message. The messages API docs list every field. When you want a key of your own, sign up here.