在本地,我的应用程序可以很好地连接到内置的 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>