Interface Producer
- All Superinterfaces:
AutoCloseable, ProducerBase
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 positiveProducerOptions.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.
-
Method Summary
Modifier and TypeMethodDescriptionsend(Invocation invocation) Sends an invocation.trySend(Invocation invocation) Attempts to send an invocation without blocking.Methods inherited from interface ProducerBase
close, flush, flushAsync, lastAcknowledgedOffset, lastSentOffset, waitAcknowledged
-
Method Details
-
send
Sends an invocation.This method waits up to
ProducerOptions.maxBlockTime()when the local buffer is full, or, when buffering is disabled, until protocol and transport readiness permit a direct write. The invocation is refused withProducerBufferExhaustedExceptionif the timeout elapses. A zero duration makes this method fail immediately under backpressure.The returned future completes when the invocation is durably committed by Restate.
- Parameters:
invocation- the invocation to send- Returns:
- a future completing, once the invocation is durably committed by Restate.
- Throws:
ProducerBufferExhaustedException- if the producer cannot admit the invocation before the configured maximum blocking time elapses, or the thread is interrupted while waitingIllegalStateException- if the producer has exhausted thelongoffset range, or a reentrant producer callback invokes this method when it would blockIllegalArgumentException- if buffering is enabled and the serialized invocation is larger thanProducerOptions.bufferMemory()ConcurrentModificationException- if the producer is used concurrently from another thread
-
trySend
Attempts to send an invocation without blocking.An
SendAttempt.Acceptedcarries the durable-acknowledgement future. ASendAttempt.Backpressuredcarries a future that completes when retrying may succeed; the notification does not reserve admission.- Parameters:
invocation- the invocation to send- Returns:
- the admission result
- Throws:
IllegalArgumentException- if buffering is enabled and the serialized invocation is larger thanProducerOptions.bufferMemory()IllegalStateException- if the producer has exhausted thelongoffset rangeConcurrentModificationException- if the producer is used concurrently from another thread
-