如何指示JMSTemplate.receive()应该使用DurableSubscriber

时间:2012-05-08 21:08:08

标签: spring jms spring-jms ems

我想在不使用xml配置的情况下执行此操作。我正在玩Spring JMS,看看它是否满足我的需求。无论如何使用

进行同步接收
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.receive() 

因此它等同于纯JMS调用:

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

无需通过xml配置?

1 个答案:

答案 0 :(得分:0)

试试这个,但你打算怎么称呼呢?

  //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();

了解更多信息 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