1 Mart 2018 Perşembe

JMS ConnectionFactory Arayüzü

Giriş
Şu satırı dahil ederiz.
import javax.jms.ConnectionFactory;
JMS sunucusuna bağlanmak için kullanılır.

constructor
Örnek
Şöyle yaparız.
@Bean
public ConnectionFactory getconnFac(InitialContext ctx) throws Exception{
  ConnectionFactory cf = null;
  try{
    cf = (ConnectionFactory) ctx.lookup(jmsProps.getConnectionFactoryJndi());
  }
  catch(NamingException ne){
    throw ne;
  }
  return cf;
}
Örnek
Şöyle yaparız. Bu sefer Spring'e ait JndiObjectFactoryBean nesnesi kullanılıyor.
/**
 * Create Jms Connection factory from Jndi Objectfactory
 * 
 * @param jndiObjectFactoryBean
 *            Jndi Object factory bean
 * @return Returns Jms Connection factory Bean
 */
@Bean(name = "jmsWlsConnectionFactory")
public ConnectionFactory jmsConnectionFactory(final JndiObjectFactoryBean
  jndiObjectFactoryBean) {
  final ConnectionFactory connectionFactory = (ConnectionFactory)
    jndiObjectFactoryBean.getObject();
  LOG.debug("ConnectoinFactory is null? {}", connectionFactory == null);
  return connectionFactory;
}
Örnek
Spring'de şöyle yaparız.
@Bean("connectionFactory")
public ConnectionFactory connectionFactory(@Qualifier("amq") TransportConfiguration
  transportConfiguration) throws JMSException {
  ActiveMQJMSConnectionFactory activeMQJMSConnectionFactory =
    new ActiveMQJMSConnectionFactory( false, transportConfiguration);
  activeMQJMSConnectionFactory.setPassword("admin");
  activeMQJMSConnectionFactory.setUser("admin");
  activeMQJMSConnectionFactory.setClientID("admin");
  return activeMQJMSConnectionFactory;
}

Hiç yorum yok:

Yorum Gönder