我想在不使用 xml 配置的情况下执行此操作。我正在玩弄 Spring JMS,看它是否满足我的需求。无论如何使用
进行同步接收JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.receive()
因此它等同于纯 JMS 调用:
MessageConsumer consumer = session.createDurableSubscriber(topic, "durable name");
Message message = consumer.receive();
无需通过xml配置?
最佳答案
试试这个,但你打算怎么调用它?
//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();
关于spring - 如何指示 JMSTemplate.receive() 应该使用 DurableSubscriber,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10506538/