当远程计算机未运行时,如何初始化远程 JMS 队列的 ConnectionFactory?
使用 JBoss 4.0.5、JBossMQ 和 Spring 2.0.8,我尝试配置 Spring 来实例化依赖于远程 JMS 队列资源的 bean。我遇到的所有示例都依赖于使用 JNDI 来查找远程 ConnectionFactory 对象等内容。
我的问题是,当尝试启动一台将消息放入远程队列的计算机时,如果远程计算机未启动,JNDI 查找就会失败,从而导致部署失败。有没有办法让 Spring 继续尝试在后台查找该对象,同时不阻止其余的部署?
Using JBoss 4.0.5, JBossMQ, and Spring 2.0.8, I am trying to configure Spring to instantiate beans which depend on a remote JMS Queue resource. All of the examples I've come across depend on using JNDI to do lookup for things like the remote ConnectionFactory object.
My problem is when trying to bring up a machine which would put messages into the remote queue, if the remote machine is not up, JNDI lookup simply fails, causing deployment to fail. Is there a way to get Spring to keep trying to lookup this object in the background while not blocking the remainder of deployment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有看到 Spring 配置,很难确定,但假设您使用 Spring 的 JndiObjectFactoryBean 来执行 JNDI 查找,那么您可以将lookupOnStartup 属性设置为 false,这即使 JNDI 目标不存在,也允许上下文启动。 JNDI 解析将在第一次使用 ConnectionFactory 时完成。
然而,这只会将问题进一步转移到链上,因为如果其他组件尝试在启动时获取 JMS
Connection
,那么您就会回到开始的地方。您可以在其他 bean 上使用lazy-init="true"
属性来防止在部署时发生这种情况,但很容易意外地将某些内容放入配置中,从而强制所有内容初始化。Iit's difficult to be sure without seeing your spring config, but assuming you're using Spring's
JndiObjectFactoryBean
to do the JNDI lookup, then you can set thelookupOnStartup
property to false, which allows the context to start up even if the JNDI target isn't there. The JNDI resolution will be done the first time the ConnectionFactory is used.However, this just shifts the problem further up the chain, because if some other component tries to get a JMS
Connection
on startup, then you're back where you started. You can use thelazy-init="true"
attribute on your other beans to prevent this from happening on deployment, but it's easy to accidentally put something in your config which forces everything to initialize.你是绝对正确的。我尝试将lookupOnStartup设置为 false 并lazy-init=true 。这只是将问题推迟到第一次尝试使用队列时。然后抛出如下异常:
此外,看起来再也没有尝试过查找。当具有远程队列的计算机恢复时,随后不会处理任何消息。这确实看起来应该完全在 J2EE 废话用例的范围内,但我没有太多运气......感觉它甚至应该是一个已解决问题。
为了完整起见,以下是我的 Spring 配置的相关部分。
You're absolutely right. I tried setting lookupOnStartup to false and lazy-init=true . This just defers the problem to the first time that the Queue is attempted to be used. Then an exception as follows is thrown:
Moreover, it looks like the lookup is never attempted again. When the machine with the remote queue is brought back up, no messages are ever processed subsequently. This really does seem like it should be well within the envelope of use cases for J2EE nonsense, and yet I'm not having much luck... It feels like it should even maybe be a solved problem.
For completion's sake, the following is the pertinent portion of my Spring configuration.