How to indicate that JMSTemplate.receive () should use DurableSubscriber

I want to do this without using xml configuration. I play with Spring JMS to find out if it fits my needs. Is there any way to make synchronous reception with

JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.receive() 

so that it is equivalent to a pure JMS call:

MessageConsumer consumer = session.createDurableSubscriber(topic, "durable name");
Message message = consumer.receive();

Without the need for customization via xml?

+3
source share
1 answer

Try it, but what do you plan to call it?

  //Create connection facotry ..in this case JndiObjectFactoryBean because i am looking up a JNDI
  org.springframework.jndi.JndiObjectFactoryBean connectionFactory = new JndiObjectFactoryBean();
  connectionFactory.setJndiName(jndiName);
  connectionFactory.setJndiTemplate(jndiTemplate);

  org.springframework.jms.core.JmsTemplate template = new org.springframework.jms.core.JmsTemplate();
  template.setConnectionFactory(connectionFactory)
  template.setPubSubDomain(false);

  Message message = template.receive();

More details http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/jms/core/JmsTemplate.html#receive%28%29

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/jms.html#jms-receiving-sync

0
source

All Articles