Microservices
Kafka
The Kafka link, a topic per pattern with consumer groups, a reply topic and correlation headers.
The Kafka link needs a Kafka broker and a C toolchain at build time: ulo-rpc-kafka depends on rdkafka, which compiles the librdkafka that rdkafka-sys bundles. Each pattern is a topic, headers are Kafka headers, and replies arrive on a reply topic with a correlation header.
app.bind(ulo_rpc::Server::new(ulo_rpc_kafka::Kafka::brokers("kafka:9092")));Kafka suits events and work that tolerates latency. A request-reply call crosses the broker twice, once on the pattern's topic and once on the reply topic, and the partition key is the client instance's id.
Settings
| Method | Effect |
|---|---|
Kafka::brokers(list) | bootstrap brokers. An ssl:// entry selects security.protocol=SSL under the crate's tls feature |
group(name) | the consumer group. Defaults to the application's root module's full type path |
reply_topic(name) | the client's reply topic |
topic_partitions(n) | partitions for topics the link creates. Each of topic_partitions and replication_factor must be at least 1 |
replication_factor(n) | replication for topics the link creates |
connect_within(Duration) | how long a server's listen may take. 30 seconds unset, timed on the app's Timer. A zero bound is refused when the server prepares, and a client's connect is not bounded by it |
codec(Codec) | JSON by default; Codec::Cbor carries raw bytes |
with_handle(Handle) | the tokio runtime, when the link is built outside one |
Behaviour
- Topics are created at
listen. A stopped server's topics therefore exist. With the broker's auto-create on, a request for an unhandled pattern creates the topic and the caller waits out its ownTimeout. Kafka signals no miss. - Requests wait for an owner. At
listenthe group's offsets are committed at the topics' end where the group has none, so a request produced while no instance consumes, or while a rebalance moves its partition, waits for the next owner. The link holds unserved requests (theunserved_holdcapability). - Events reach one instance. An event left at the default is consumed through the group and handled by one instance. An event declared
#[ulo_rpc::event("pattern", every_instance)]is read by a consumer of each instance's own. That consumer is outside any group, commits nothing, and is assigned every partition of its topic at the topic's end whenlistenruns. A partition added to such a topic afterwards is not read by an instance already running, and the server logs a warning naming the topic and both counts. listenwaits for assignment. The server'slistenreturns once its two consumers of its own, the control topic's and the every-instance events', are assigned. A record produced to those topics afterwards is read. It fails withConnectTimedOutwhen that takes longer thanconnect_within.- Rolling out a new handler. Kafka accepts that first commit only while the group has no member. The link therefore anchors a topic only when the group's first instance listens. A handler added by a deployment that rolls out while the group runs gets a topic with no committed offset. A request produced to it before its first assignment, or during a rebalance, is skipped and its caller sees its own
Timeout. Stopping every instance before starting the new version anchors it. - Replies are durable. A reply published while the client is disconnected waits on its reply topic for the client to reconnect.
- In-flight limit. At
max_inflight(1,024 unset) the group consumer pauses its partitions until a request settles, so excess requests wait in their topics. - Frame limit. The producer's
message.max.bytes, 1,000,000 bytes. A broker configured lower refuses with the same error. - Acknowledgement. Kafka acknowledges no request. An offset is stored when its handler completes and committed by the next auto-commit.
- Reserved headers.
ulo-reply-toandulo-correlation-idcarry the reply address and correlation. A streamed request usesulo-t: openandulo-t: opened, and its items, end andcanceltravel on the topiculo.rpc.control, which every instance reads in full. - Drain. The server pauses its partitions and commits.
- Shutdown threads. A librdkafka consumer's drop polls until the broker confirms, so the link drops each consumer on a thread of its own. The server's
closedoes not wait for them. Once the broker is gone, the drop can block a thread without bound, never the tokio runtime and never the process's exit.