3

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

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

使其等效于纯 JMS 调用:

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

不需要通过xml配置?

4

1 回答 1

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

于 2013-02-05T10:17:47.153 回答