问题
Is it possible to get the identifier of the MDB instance that is executing? I have a pool of MDB (e.g. 10) and I set in my messages the property JMSXGroupID in order to have the same MDB instance processing all the messages with same JMSXGroupID. To check that I'd like to log an identifier of the current MDB instance: how can I get that information?
回答1:
There is no such identifier according to EJB specification, although probably it may be achieved using your MDB vendor API.
You can always create unique MDB identifier in @PostConstruct method, but in my opinion it is not a good solution, as all beans in the pool should be treated the same way!
Maybe you could set JMSXGroupID as a message header, and use message selector in MDB to process it with given MDB implementation, so that there would be more than one bean listening on given queue (example)?
Or you could create generic MDB bean which will extract mentioned previously header and invoke EJB singleton bean with state you are willing to achieve per JMSXGroupID.
来源:https://stackoverflow.com/questions/42907214/messagedrivenbean-instance-identifier