25 Eylül 2019 Çarşamba

SpringJMS DefaultMessageListenerContainer Sınıfı

Giriş
Şu satırı dahil ederiz.
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.connection.SingleConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.jms.support.converter.MessageType;
constructor
Şöyle yaparız.
DefaultMessageListenerContainer defaultMessageListenerContainer =
  new DefaultMessageListenerContainer();
setConcurrentConsumers metodu
Örnek
Şöyle yaparız.
<bean id="jmsContainer"
  class="org.springframework.jms.listener.DefaultMessageListenerContainer">
  <property name="connectionFactory" ref="connectionFactory"/>
  <property name="destination" ref="destination"/>
  <property name="messageListener" ref="transactionMessageListener"/>
  <property name="sessionTransacted" value="true"/>
  <property name="concurrentConsumers" value="1"/>
</bean>
Örnek
Şöyle yaparız.
ConnectionFactory connectionFactory = ...;
defaultMessageListenerContainer.setConnectionFactory(connectionFactory);
Örnek
IBM'e bağlanmak için şu satırı dahil ederiz.
import com.ibm.mq.jms.MQQueueConnectionFactory;
Şöyle yaparız.
public MQQueueConnectionFactory connectionFactory3() {
  MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
  ...
  return connectionFactory;
}

@Bean
public DefaultMessageListenerContainer listenerContainer() throws JMSException {
  DefaultMessageListenerContainer defMsgListCont = new DefaultMessageListenerContainer();
  defMsgListCont.setConnectionFactory(connectionFactory3());
  defMsgListCont.setDestination(jmsDestinationResolverReceiver());
  defMsgListCont.setMessageListener(messageListenerReciever1);
  defMsgListCont.afterPropertiesSet();
  return defMsgListCont;
}
setDestination metodu
Örnek
Şöyle yaparız.
Topic topic = ...;
defaultMessageListenerContainer.setDestination(topic);
Örnek
IBM'e bağlanmak için elimizde şöyle bir kod olsun
@Bean
public Destination jmsDestinationResolverSender() throws JMSException {
  return new MQQueue(updateQueue);
}
Şöyle yaparız.
@Bean
public DefaultMessageListenerContainer listenerContainer() throws JMSException {
  DefaultMessageListenerContainer defMsgListCont = new DefaultMessageListenerContainer();
  ...
  defMsgListCont.setDestination(jmsDestinationResolverReceiver());
  return defMsgListCont;
}
setMessageConverter metodu
Örnek
Şöyle yaparız.
SimpleMessageConverter messageConverter = ...;
defaultMessageListenerContainer.setMessageConverter(messageConverter);

Hiç yorum yok:

Yorum Gönder