24 Şubat 2020 Pazartesi

SpringJMS DefaultJmsListenerContainerFactoryConfigurer Sınıfı

Giriş
Şu satırı dahil ederiz
import org.springframework.boot.autoconfigure.jms
.DefaultJmsListenerContainerFactoryConfigurer;
configure metodu - ConnectionFactory + JmsListenerContainerFactory 
Birinci parametre JMS sunucusuna bağlanmak içindir.
İkinci parametre JMSListener yaratmak içindir.

Örnek
Şöyle yaparız.
@Bean
public ConnectionFactory connectionFactory() {

  ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
  try {
    connectionFactory.setBrokerURL("failover:(tcp://activemq-01:61616,
      tcp://activemq-02:61616)?randomize=false&maxReconnectDelay=3000&
      maxReconnectAttempts=50");
    connectionFactory.setUserName("abcxyz");
    connectionFactory.setPassword("abcxyz");
  }catch(Exception e) {
    e.printStackTrace();
  }
  return connectionFactory;
}      

@Bean
public JmsListenerContainerFactory<?> topicListenerFactory(
  ConnectionFactory connectionFactory,
  DefaultJmsListenerContainerFactoryConfigurer configurer) {

  DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  factory.setSubscriptionDurable(true);
  factory.setClientId("ClientID");
  configurer.configure(factory, connectionFactory);
  factory.setPubSubDomain(true);
  return factory;
}

Hiç yorum yok:

Yorum Gönder