There’s a new handy
org.jpos.transaction.TxnId class in the jPOS-EE
txn module that can be used to generate transaction ids in multi-node systems.
The id is composed of:
- 1-digit century
- 2-digits year
- 3-digits day of year
- 5-digits second of day
- 3-digits node id
- 5-digits transaction id
A typical ID long value would look like this:
173000702600000001, and the
toString() method would show as
017-300-07026-000-00001 and the
toRrn() method would return
TxnId also has a handy
toRrn() method that can be used to create (and parse) 12-characters strings suitable to be used as retrieval reference numbers.
TxnId can be used instead of UUIDs. It puts less pressure in the database index and provides chronological order.
NOTE: The last two groups,
transaction-id are supposed to be unique.
transaction-id is easy to get from the transaction manager and
node-id is a tricky one, user has to ensure each node has a unique
node-id to avoid collisions.
TxnId txnId = TxnId.create(DateTime.now(), 0, id);