在本地,我的应用程序可以很好地连接到内置的netty ConnectionFactory,我在启动或发送主题消息方面没有任何问题。我的本地包是独立的JBoss 5.1和独立的HornetQ。
但是,当部署到我们的DEV服务器(运行集群JBoss 5.1和集群HornetQ)时,我无法连接,获得以下堆栈跟踪:
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/eShowroom]] (main) Exception sending context initialized event to listener instance of cla>\ss org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'topicConnectionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: ConnectionFactory not bound
我正在尝试使用默认的内置netty连接器,除了我自己的JMS主题之外没有额外的配置。我相对没有意识到DEV服务器设置,因为它不受我的控制,并且相当黑盒子给我。
applicationContext.xml (在$JBOSS_HOME/server/default/deploy/application.war/WEB-INF
中):
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">jnp://${jboss.bind.address:localhost}:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jboss.naming</prop>
</props>
</property>
</bean>
<bean id="topicConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate"></property>
<property name="jndiName" value="/ConnectionFactory"></property>
</bean>
<bean id="cacheTopic" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate"></property>
<property name="jndiName" value="/topic/myCacheTopic"></property>
</bean>
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate"/>
<property name="cache" value="true"/>
</bean>
<bean id="messageSendTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="topicConnectionFactory"/>
<property name="destinationResolver" ref="jmsDestinationResolver"/>
<property name="pubSubDomain" value="true"/>
</bean>
hornetq-jms.xml (在$JBOSS_HOME/server/default/deploy/hornetq.sar
)
<connection-factory name="NettyConnectionFactory">
<xa>true</xa>
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="/ConnectionFactory"/>
<entry name="/XAConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="NettyThroughputConnectionFactory">
<xa>true</xa>
<connectors>
<connector-ref connector-name="netty-throughput"/>
</connectors>
<entries>
<entry name="/ThroughputConnectionFactory"/>
<entry name="/XAThroughputConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="InVMConnectionFactory">
<xa>true</xa>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
<entry name="java:/XAConnectionFactory"/>
</entries>
</connection-factory>
我可以轻松发现本地和DEV之间的唯一区别在于hornetq-configuration.xml。
DEV hornetq-configuration.xml (与hornetq-jms.xml相同的路径)
<broadcast-groups>
<broadcast-group name="bg-group1">
<group-address>${hornetq.broadcast.bg-group1.address:231.7.7.7}</group-address>
<group-port>${hornetq.broadcast.bg-group1.port:9876}</group-port>
<broadcast-period>5000</broadcast-period>
<connector-ref>netty</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="dg-group1">
<group-address>${hornetq.discovery.dg-group1.address:231.7.7.7}</group-address>
<group-port>${hornetq.discovery.dg-group1.port:9876}</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>netty</connector-ref>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
</cluster-connections>
答案 0 :(得分:0)
因此,事实证明,无论出于何种原因,这都是群集环境中的计时问题。需要连接工厂的bean只是被迫等到其他所有东西都启动并运行才开始旋转。