How can I schedule message? #7490
-
|
Based on https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-51.md I created a stream: And here's how I publish a message: package main
import (
"log"
"github.com/nats-io/nats.go"
)
func main() {
nc, err := nats.Connect(nats.DefaultURL)
if err != nil {
log.Fatal(err)
}
defer nc.Close()
msg := nats.NewMsg("test_stream.subject")
msg.Header.Add("Nats-Schedule", "@at 2025-10-29T23:00:00")
msg.Header.Add("Nats-Schedule-Target", "test_stream.123")
msg.Data = []byte("help me")
err = nc.PublishMsg(msg)
if err != nil {
log.Fatal(err)
}
}But it immediately goes to the handler: nats sub 'test_stream.>'
16:49:53 Subscribing on test_stream.>
[#1] Received on "test_stream.subject"
Nats-Schedule: @at 2025-10-29T23:00:00
Nats-Schedule-Target: test_stream.123
help me |
Beta Was this translation helpful? Give feedback.
Answered by
MauriceVanVeen
Oct 29, 2025
Replies: 1 comment 1 reply
-
|
This is intended. You just received the schedule itself which is stored on the same stream. Changing the # Create the stream, allowing message scheduling.
nats str add test_stream --subjects 'test_stream.>' --defaults --allow-schedules
# In another window, start listening to the messages on the stream.
nats sub --stream test_stream
# Use JetStream publishing to know the schedule was persisted into the stream.
nats pub -J 'test_stream.subject' 'help me' -H "Nats-Schedule: @at 1970-01-01T00:00:00Z" -H "Nats-Schedule-Target: test_stream.123"The other window has then received both messages, the schedule itself, and after the delay the delayed message: Summarizing:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
sheldygg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is intended. You just received the schedule itself which is stored on the same stream. Changing the
Nats-Schedule: @at <ts>to be earlier, you'll see it gets delivered after the specified delay.The other window has then received both messages, the s…