hermes-broker-client
gRPC client library for the Hermes message broker — publish and subscribe to messages with fire-and-forget semantics and automatic reconnection.
Hermes is a lightweight, high-performance message broker built in Rust. It uses trie-based subject routing with dot-separated topics (like orders.eu.created), supports broadcast fanout and load-balanced queue groups, and communicates over gRPC streaming.
This crate is a library that provides the two main building blocks for interacting with a running broker: Publisher and Subscriber. Add it as a dependency to your project and use it to publish and consume messages from any Rust application.
Features
- Fire-and-forget publishing — messages are queued and streamed, no per-message ack overhead
- Automatic reconnection — the publisher transparently reconnects on stream failure (2 s backoff)
- Wildcard subscriptions —
*matches one token,>matches one or more trailing tokens - Queue groups — load-balanced round-robin delivery across group members
- mTLS support — optional mutual TLS for production deployments
Getting Started
Add the dependency:
Or in your Cargo.toml:
[]
= "0.7"
You'll also need a running Hermes broker — see hermes-broker-server.
Publisher Example
A Publisher streams messages to the broker with fire-and-forget semantics — publish() returns as soon as the message is queued locally, without waiting for a broker acknowledgment. If the connection drops (broker restart, network hiccup), the publisher automatically reconnects in the background with a 2-second backoff.
use Bytes;
use ;
async
Tip:
Publisher::newis not async — it spawns a background tokio task and returns immediately.
Subscriber Example
A Subscriber opens a bidirectional gRPC stream with the broker. You can subscribe to one or more subjects (including wildcard patterns), then receive matching messages via recv(). Dropping the subscriber closes the stream and triggers server-side cleanup.
use ;
async
Subjects are dot-separated tokens. Wildcards are only valid in subscriptions:
| Pattern | Matches | Doesn't match |
|---|---|---|
orders.eu.created |
orders.eu.created |
orders.us.created |
orders.*.created |
orders.eu.created, orders.us.created |
orders.eu.deleted |
orders.> |
orders.eu, orders.eu.created |
orders |
Queue Groups
By default, all subscribers on a subject receive every message (fanout / broadcast). If you want to distribute work across multiple consumers instead, subscribe with a queue group name — the broker delivers each message to exactly one member of the group using round-robin.
// Both subscribers share the "workers" queue group.
// A message published to "jobs.process" goes to exactly one of them.
subscriber1.subscribe.await?;
subscriber2.subscribe.await?;
This is useful for horizontally scaling consumers: spin up more instances with the same group name and the broker balances the load automatically.
Request / Reply
Hermes is primarily a fire-and-forget broker, but you can implement request/reply on top of it. The pattern works like this: the requester subscribes to a unique "inbox" subject, publishes a message with reply_to set to that inbox, and the responder publishes its reply back to the reply_to subject.
use Bytes;
use ;
async
API Overview
| Type | Description |
|---|---|
connect() |
Connect to a broker (plaintext or mTLS) |
Publisher |
Fire-and-forget publisher with auto-reconnect |
Subscriber |
Subscribe to subjects and receive messages |
TlsConfig |
mTLS configuration (CA cert, client cert & key) |
PublishError |
Returned when the publisher is disconnected |
SubscribeError |
Returned when the subscriber is disconnected |
Minimum Supported Rust Version
This crate requires Rust 1.85+ (edition 2024).
License
Licensed under either of MIT or Apache-2.0 at your option.