2012-05-08 20 views
3

我想在不使用xml配置的情況下執行此操作。我正在與Spring JMS玩弄,看看它是否符合我的需求。反正有做同步的接收使用的如何指示JMSTemplate.receive()應使用DurableSubscriber

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

,使其等同於純JMS電話:

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

,而無需通過XML配置?

回答

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