Closed jkernech closed 8 years ago
The gtm.TimestampGenerator
is typed as a function. So you can use code like this if you just have a timestamp you want to use:
var ts bson.MongoTimestamp = 0
ops, errs := gtm.Tail(session, >m.Options {
After: func (session *mgo.Session, options *gtm.Options) bson.MongoTimestamp {
return ts
},
})
Regarding why this field is a function and not simply a bson.MongoTimestamp
: I don't have a great reason. It's a case of an implementation detail leaking into the interface. If you look at the gtm.go source you will see the default function, gtm.LastOpTimestamp
, which reads and returns the most recent timestamp from the oplog. If After is provided it directly replaces this default function.
If your program saves the timestamp of the last event processed using gtm in Mongo, then your After function could be used to retrieve that timestamp using the mgo.Session in order to "resume" tailing the oplog where you last left off.
Hi @rwynn, I have now a better understanding of how it works and more importantly why you chose this design :) Thank you for this detailled answer !
I have tried to specify the
After
property ofgtm.option
but when I try to specify theAfter
property with aMongoTimestamp
, I have the following error :Could you provide an example (usage of the field) and explain why you decided not to use the type
bson.MongoTimestamp
?Thanks