Skip to content

[QUESTION] - How to restrict consuming previously consumed messages? #1502

Closed Answered by Jarema
sujit-baniya asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, because you create a new consumer every single time you call that method.

Here is a full example with the new JetStream API.

    nc, _ := nats.Connect(nats.DefaultURL)
	js, _ := jetstream.New(nc)

	ctx := context.Background()
	// Get the stream. You can also create it.
	stream, err := js.Stream(ctx, "ORDERS")
	if err != nil {
		fmt.Println("Error getting stream info:", err)
	}
    // Create a consumer. If consumer with this name exists, it will be updated.
    // If it exists with the same config, it will just give you the handle to it.
    // This consumer will persist through the restarts.
	consumer, err := stream.CreateOrUpdateConsumer(ctx, jetstream.ConsumerConfig{
		Durable:       

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sujit-baniya
Comment options

@Jarema
Comment options

Answer selected by sujit-baniya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants