Skip to content
Try Hanzo
Language: English (United States)

Hanzo PubSub

The bus everything else rides

GitHub

NATS JetStream

stream EVENTS · events.>

373839404142
analyticsack
auditack
queue group

Put it between your services

Free tier includes 1M messages/month.

View on GitHub
events.go
nc, _ := nats.Connect("nats://pubsub.hanzo.ai:4222")
js, _ := nc.JetStream()

// Create a durable stream
js.AddStream(&nats.StreamConfig{
    Name:     "EVENTS",
    Subjects: []string{"events.>"},
    Storage:  nats.FileStorage,
    Replicas: 3,
})

// Publish
js.Publish("events.user.signup", []byte(`{"id":"usr_123"}`))

// Durable consumer with ack
sub, _ := js.PullSubscribe("events.>", "my-service")
msgs, _ := sub.Fetch(10)
for _, msg := range msgs {
    process(msg.Data)
    msg.Ack()
}

More than pub/sub

  1. 01 / 06

    Streams write it down

    A stream captures the subjects you name and keeps them by age, by count or by bytes. A consumer starts at the beginning, at the newest message, at a sequence number or at a wall-clock time, and reads at the original pace or as fast as it can take them.

  2. 02 / 06

    Acked, so nothing goes quiet

    A message is redelivered until a consumer acknowledges it. Publishers that stamp a message id get duplicates collapsed inside a window — two minutes unless you say otherwise. Ack every message, ack a sequence to cover everything below it, or ask for no acks at all when fire-and-forget is what you meant.

  3. 03 / 06

    Key-value buckets

    A bucket is a stream that keeps the last value per key, so you get watches, per-key history and expiry from the same server and the same connection. It is where Hanzo Stream keeps its consumer offsets.

  4. 04 / 06

    Request-Reply

    Send to a subject and wait for one answer. Put several instances of a service in a queue group on that subject and each request goes to exactly one of them — load balancing with nothing in front of them doing it.

  5. 05 / 06

    Object Store

    Payloads too big to be a message are chunked into a stream and put back together on the way out, with a watch for when one changes. Same connection, same credentials, no second system to stand up.

  6. 06 / 06

    Accounts, not passwords

    An account walls one tenant's subjects off from another's. Credentials are nkeys or signed JWTs rather than a shared secret, permissions are granted per subject, and TLS covers the wire.

Publish and Subscribe

Paste and ship

Paste this into any agent. It reads the skill manifest and calls Pubsub from there.

Agent prompt
Read https://hanzo.ai/skill.md and use Hanzo Pubsub in my project. Start with: hanzo pubsub publish
Client port
4222
From any point
Replay
Written to disk
Durable
Set per stream
Replicas

Get PubSub

Pub/sub messaging