Hello! happy new year to everybody !
I have the following question: I have an EJB application which sends some JMS messages:
@Resource(mappedName = "java:jboss/jms/queue/dlmsQueue")
private Queue queueExample;
@Resource(mappedName = "java:/ConnectionFactory")
private ConnectionFactory cf;
private Connection connection;
public void sendMessage(String msg) {
connection = cf.createConnection();
. . . .
}
The JMS ConnectionFactory and the Queue are injected, however the Connection is created every time. Is this a good pattern or should I cache the Connection object ? (maybe in a @PostConstruct method)
I have read here https://community.jboss.org/wiki/ShouldICacheJMSConnectionsAndJMSSessions that the JCA layer might be able to intercept and cache the call, however I would like to check it somehow.
Any help ?
Thanks
Mylos
You should inject "java:/JmsXA" and then you won't have to worry about caching anything because that connection factory is pooled (i.e. it is a <pooled-connection-factory>). Check out the messaging doc for AS7 for further discussion of the different kinds of connection factories available.