java - Should we ever call setClientId() on the connection factory? -
this in context of creating durable subscription.
there setclientid() in defaultmessagelistenercontainer , 1 in singleconnectionfactory.
my understanding :
- durable subscription consumer/subscriber.
- different consumers should capable of using different client ids.
- different consumers should able share connection.
- there 1 (listenercontainer,listener) pair per consumer.
so, makes sense setclientid() @ listenercontainer.
but, why there setclientid() @ connection factory level ?
even though singleconnectionfactory has single connection, connection shared multiple consumers, across multiple sessions. right ? needless more dangerous cachingconnectionfactory (which inherits method singleconnectionfactory).
extended version: can 1 should not use setclientid() on single/cachingconnectionfactory ? made more imperative following statement in defaultmessagelistenercontainer's setclientid():
furthermore, client id can assigned if original connectionfactory hasn't assigned one
so, if accidentally setclientid on cachingconnectionfactory, future sets of client id on defaultmessagelistenercontainer no-ops !
but, why there setclientid() @ connection factory level ?
setclientid() on connection factory used administratively set client id, prevent consumer applications setting manually; in fact, according jms spec, if client id set client when set factory, exception thrown.
can 1 should not use setclientid() on single/cachingconnectionfactory?
if need create durable subscriptions different subscribers, each own client id, use subscriber.setclientid(), because if use connectionfactory.setclientid() , attempt create multiple connections same factory client id set, factory throw exception complaining "connection clientid connected."
personally, having flexibility , complete control in code, use subscriber.setclientid()
Comments
Post a Comment