()
| 346 | } |
| 347 | |
| 348 | func 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 |
nothing calls this directly
no test coverage detected