MCPcopy
hub / github.com/nats-io/nats.go / ExampleJetStreamManager

Function ExampleJetStreamManager

example_test.go:348–388  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

346}
347
348func ExampleJetStreamManager() {
349 nc, _ := nats.Connect("localhost")
350
351 js, _ := nc.JetStream()
352
353 // Create a stream
354 js.AddStream(&nats.StreamConfig{
355 Name: "FOO",
356 Subjects: []string{"foo"},
357 MaxBytes: 1024,
358 })
359
360 // Update a stream
361 js.UpdateStream(&nats.StreamConfig{
362 Name: "FOO",
363 MaxBytes: 2048,
364 })
365
366 // Create a durable consumer
367 js.AddConsumer("FOO", &nats.ConsumerConfig{
368 Durable: "BAR",
369 })
370
371 // Get information about all streams (with Context JSOpt)
372 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
373 defer cancel()
374 for info := range js.StreamsInfo(nats.Context(ctx)) {
375 fmt.Println("stream name:", info.Config.Name)
376 }
377
378 // Get information about all consumers (with MaxWait JSOpt)
379 for info := range js.ConsumersInfo("FOO", nats.MaxWait(10*time.Second)) {
380 fmt.Println("consumer name:", info.Name)
381 }
382
383 // Delete a consumer
384 js.DeleteConsumer("FOO", "BAR")
385
386 // Delete a stream
387 js.DeleteStream("FOO")
388}
389
390// A JetStreamContext is the composition of a JetStream and JetStreamManagement interfaces.
391// In case of only requiring publishing/consuming messages, can create a context that

Callers

nothing calls this directly

Calls 10

ConnectMethod · 0.80
JetStreamMethod · 0.80
AddStreamMethod · 0.65
UpdateStreamMethod · 0.65
AddConsumerMethod · 0.65
StreamsInfoMethod · 0.65
ContextMethod · 0.65
ConsumersInfoMethod · 0.65
DeleteConsumerMethod · 0.65
DeleteStreamMethod · 0.65

Tested by

no test coverage detected