Interface Producer

All Superinterfaces:
AutoCloseable, ProducerBase

@Experimental public interface Producer extends ProducerBase
Sends invocations to Restate with at-least-once delivery.
try (IntegrationClient client = IntegrationClient.builder("http://localhost:8080").build();
    Producer producer = client.newProducer()) {
  producer.send(
      Invocation.create()
          .setServiceName("Greeter")
          .setHandlerName("greet")
          .setBody(payload));
  producer.flush();
}

Buffering

With a positive ProducerOptions.bufferMemory(), send(Invocation) first admits the invocation to a byte-bounded local buffer while it waits to be handed to the transport. A value of zero disables local buffering, so send instead waits until the protocol and transport are writable. Either wait is bounded by ProducerOptions.maxBlockTime(). The returned future tracks durable acknowledgement, not admission. Send several invocations without awaiting each future, then use ProducerBase.flush() or ProducerBase.flushAsync() to await them in bulk. ProducerBase.close() does not flush.

Non-blocking admission

For event-loop or callback-based code, trySend(Invocation) does not wait for admission. SendAttempt.Accepted contains the durable-acknowledgement future. On SendAttempt.Backpressured, use SendAttempt.Backpressured.ready() to schedule a retry on the event loop; readiness is a notification, not an admission reservation.
static CompletableFuture<SendResult> sendWithoutBlocking(
    Producer producer, Invocation invocation, Executor eventLoop) {
  SendAttempt attempt = producer.trySend(invocation);
  if (attempt instanceof SendAttempt.Accepted accepted) {
    return accepted.acknowledgement();
  }
  return ((SendAttempt.Backpressured) attempt)
      .ready()
      .thenComposeAsync(
          ignored -> sendWithoutBlocking(producer, invocation, eventLoop), eventLoop);
}

The client assigns monotonically increasing offsets from 0 through Long.MAX_VALUE. Producer-level deduplication is disabled; set an idempotency key on an invocation when handler-level deduplication is required.

A producer is not thread-safe and fails fast with ConcurrentModificationException if used from more than one thread at once.