nsqio / go-nsq

The official Go package for NSQ
MIT License
2.59k stars 444 forks source link

Is Message.ID unique id ? #250

Closed lougxing closed 5 years ago

lougxing commented 5 years ago

type Message struct {
    ID        MessageID
        Body []byte
....
}

Is Message.ID global unique id ?  Is it used as a key in map/redis ?
mreiferson commented 5 years ago

If your cluster is configured to ensure that --node-id for each nsqd is unique, then yes, MessageID values should be globally unique.

However, I wouldn't rely on this and would recommend you instead include your own identifiers in your message bodies that you ensure are globally unique.

ploxiln commented 5 years ago

Some further notes:

The nsq MessageID is currently only unique within a topic (and only if nsqd node IDs are different), other topics can easily have a message with the same MessageID.

We only really want to promise that a MessageID will be unique for a particular connection between an nsq consumer and an nsqd. The only use of the MessageID should be for finishing or re-queuing a message. We want to be able to change the way these IDs are generated in the future, to be more efficient, and maybe robust against time going backwards, though I'm not sure if we will ...

mreiferson commented 5 years ago

The nsq MessageID is currently only unique within a topic

Ahh right, forgot about this!

lougxing commented 5 years ago

thanks.