Giriş
Şu satırı dahil ederizz
Şu satırı dahil ederizz
import org.springframework.jms.connection.CachingConnectionFactory;
Açıklaması şöyle. ConnectionFactory nesnelerini gerçekten cache'leyerek kullanılır
Although both the PooledConnectionFactory and the CachingConnectionFactory state that they each pool connections, sessions and producers, the PooledConnectionFactory does not actually create a cache of multiple producers. It simply uses a singleton pattern to hand out a single cached producer when one is requested. Whereas the CachingConnectionFactory actually creates a cache containing multiple producers and hands out one producer from the cache when one is requested.Açıklaması şöyle
In order to connect and be able to send/receive messages, we need to configure a ConnectionFactory.Şöyle yaparızz
A ConnectionFactory is one of the JMS administered objects which are preconfigured by an administrator. A client with the help of the configuration will make the connection with a JMS provider.
Spring provides 2 types of ConnectionFactory:
- SingleConnectionFactory – is an implementation of ConnectionFactory interface, that will return the same connection on all createConnection() calls and ignore calls to close()
- CachingConnectionFactory – extends the functionality of the SingleConnectionFactory and adds enhances it with a caching of Sessions, MessageProducers, and MessageConsumers
destroy metodu
@Bean(destroyMethod = "destroy")
public ConnectionFactory connectionFactory(JmsProperties appProperties) {
ActiveMQConnectionFactory cf = ...
return new CachingConnectionFactory(cf) {
@Override
public void destroy() {
super.destroy();
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
...
}
System.out.println("CachingConnectionFactory is destroyed!");
}
};
}
Hiç yorum yok:
Yorum Gönder