DefaultJmsListenerContainerFactory etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
DefaultJmsListenerContainerFactory etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

11 Mayıs 2020 Pazartesi

SpringJMS DefaultJmsListenerContainer Sınıfı

Giriş
DefaultJmsListenerContainerFactory tarafından yaratılır. Mesajları asenkron olarak okur ve işler.

setConcurrency metodu
Açıklaması şöyle.
Notice the concurrency="10-50" property above. This is a simplified configuration for setting the concurrentConsumers=10 and the maxConcurrentConsumers=50 properties of the DMLC. This tells the DMLC to always start up a minimum of 10 consumers.
setConcurrentConsumers metodu
Açıklaması şöyle. Default olarak 1 tane consumer ile başlar. Bu metod yerine setConcurrency() metodu kullanılabilir.
The Spring DefaultMessageListenerContainer (DMLC) is a highly flexible container for consuming JMS messages that can handle many different use cases via the numerous properties that it provides. For the situation mentioned above, the DMLC offers the ability to dynamically scale the number of consumers. That is, as the number of messages available for consumption increases, the DMLC can automatically increase and decrease the number of consumers. To configure the DMLC to automatically scale the number message consumers, the concurrentConsumers property and the maxConcurrentConsumers property are used.
setTaskExecutor metodu
Açıklaması şöyle.
So, the main use-case for setting the task executor is for integration with an existing thread pool. The default executor will already scale according to the number of concurrent consumers you configure. 

7 Mart 2018 Çarşamba

SpringJMS DefaultJmsListenerContainerFactory Sınıfı

Giriş
DefaultJmsListenerContainer nesnesi yaratır. Normalde bu sınıfı Spring yaratıyor. Bazı özelliklerini değiştirmek istersek elle kodlamamız gerekir.

Örnek
Şöyle yaparız
@Configuration
static class JmsConfiguration {

  @Bean
  public DefaultJmsListenerContainerFactory myFactory(
    DefaultJmsListenerContainerFactoryConfigurer configurer) {
    
    DefaultJmsListenerContainerFactory factory =
      new DefaultJmsListenerContainerFactory();
    configurer.configure(factory, connectionFactory());
    factory.setMessageConverter(myMessageConverter());
    return factory;
  }
}
Daha sonra kullanmak için şöyle yaparız
@Component
public class MyBean {

  @JmsListener(destination = "someQueue", containerFactory="myFactory")
  public void processMessage(String content) {
    // ...
  }
}
constructor
Şöyle yaparız.
DefaultJmsListenerContainerFactory fact =
  new DefaultJmsListenerContainerFactory();
setConcurrency metodu
Şöyle yaparız
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
  DefaultJmsListenerContainerFactory factory =
    new DefaultJmsListenerContainerFactory();
  factory.setConnectionFactory(connectionFactory());
  factory.setConcurrency("1-1");

  factory.setMessageConverter(jacksonJmsMessageConverter());
  return factory;
}
setConnectionFactory metodu
Şöyle yaparız.
ConnectionFactory connFact = ...;
fact.setConnectionFactory(connFact);
setRecoveryInterval metodu
Şöyle yaparız.
fact.setRecoveryInterval(10000L);
setSessionTransacted metodu
Şöyle yaparız.
fact.setSessionTransacted(true);
setSubscriptionDurable metodu
Örnek
Şöyle yaparız
@Bean
public JmsListenerContainerFactory jmsFactoryTopic(ConnectionFactory connectionFactory,
                                DefaultJmsListenerContainerFactoryConfigurer configurer) {
  DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  configurer.configure(factory, connectionFactory);
  factory.setPubSubDomain(true);
  factory.setClientId("produtor");
  factory.setSubscriptionDurable(true);
  return factory;
}