3

我正在尝试评估 HornetQ 以及将其嵌入到 spring 应用程序中的可能性。从一个简单的设置开始,我只是尝试按如下方式对其进行初始化。除了“你可以”这一事实之外,我没有找到太多关于如何做到这一点的文档。

我正在使用 Spring 3 和 HornetQ 2.1.1GA

我的 Spring 配置看起来像这样,但是如果有更简单的清洁配置会更好。我首先想要简约的方法,然后在此基础上进行构建。:

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


<bean name="mbeanServer" class="java.lang.management.ManagementFactory" factory-method="getPlatformMBeanServer" />

<bean name="fileConfiguration" class="org.hornetq.core.config.impl.FileConfiguration" init-method="start" destroy-method="stop" />

<bean name="hornetQSecurityManagerImpl" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl" />

<!-- The core server -->
<bean name="hornetQServerImpl" class="org.hornetq.core.server.impl.HornetQServerImpl">
 <constructor-arg ref="fileConfiguration" />
 <constructor-arg ref="mbeanServer" />
 <constructor-arg ref="hornetQSecurityManagerImpl" />
</bean>

<!-- The JMS server -->
<bean name="jmsServerManagerImpl" class="org.hornetq.jms.server.impl.JMSServerManagerImpl" init-method="start" destroy-method="stop" >
 <constructor-arg ref="hornetQServerImpl" />
</bean>

    <bean name="connectionFactory" class="org.hornetq.jms.client.HornetQConnectionFactory" >
 <constructor-arg>
  <bean class="org.hornetq.api.core.TransportConfiguration">
   <constructor-arg value="org.hornetq.integration.transports.netty.NettyConnectorFactory" />
   <constructor-arg>
    <map key-type="java.lang.String" value-type="java.lang.Object">
     <entry key="port" value="5445"></entry>
    </map>
   </constructor-arg>
  </bean>
 </constructor-arg>
</bean>

<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
 <property name="connectionFactory" ref="connectionFactory"></property>
</bean>

</beans>

使用此配置,我收到错误:

SEVERE: Unable to deploy node [queue: null] DLQ
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
...
29-Dec-2010 18:16:34 org.hornetq.core.logging.impl.JULLogDelegate error
SEVERE: Unable to deploy node [queue: null] ExpiryQueue
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
...
9-Dec-2010 18:16:34 org.hornetq.core.logging.impl.JULLogDelegate error
SEVERE: Unable to deploy node [queue: null] ExampleQueue
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
 at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)

它必须与 JNDI 明显相关,但我希望从适当的简约配置开始,然后再对其进行扩展。HornetQ 配置文件是发行版附带的默认配置文件(默认队列、默认用户等)

4

1 回答 1

2

您需要定义要添加到服务器的 JMS 队列,并为每个队列指定一个空的 JNDI 绑定列表。为此,请将 JMSConfigurationImpl 添加到您的 JMSServerManagerImpl bean 定义中。例如,如果您需要定义一个名为“testqueue”的队列:

  <bean id="hornetQJmsConfig" class="org.hornetq.jms.server.config.impl.JMSConfigurationImpl">
    <constructor-arg index="0">
      <list/>
    </constructor-arg>
    <!-- Queue configurations -->
    <constructor-arg index="1">
      <list>
        <bean class="org.hornetq.jms.server.config.impl.JMSQueueConfigurationImpl">
          <!-- Name -->
          <constructor-arg index="0" value="testqueue"/>
          <!-- Selector -->
          <constructor-arg index="1"><null/></constructor-arg>
          <!-- Durable queue -->
          <constructor-arg index="2" value="true"/>
          <!-- JNDI bindings, empty list for none -->
          <constructor-arg index="3"><list/></constructor-arg>
        </bean>
      </list>
    </constructor-arg>
    <!-- Topic configurations -->
    <constructor-arg index="2">
      <list/>
    </constructor-arg>
  </bean>

由于第二个和第三个构造函数参数采用队列和主题配置列表,因此您可以添加任意数量的队列和主题。对于不止一两个,最好创建一个 Spring 模板对象。

于 2011-01-18T10:17:51.693 回答