0

我正在尝试使用 Jboss 为 JMS 编写示例程序。我通过以下链接了解如何将 Jboss 用于 JMS

http://docs.jboss.org/jbossmessaging/docs/usermanual-2.0.0.beta1/html/using-jms.html

查找 ConnectionFactory 时出现异常,即“iniCtx.lookup("ConnectionFactory")”

javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] 
at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1058) 
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1127) 
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:478) 
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471) 
at javax.naming.InitialContext.lookup(Unknown Source) 
at MessageProducer.main(MessageProducer.java:46) 
Caused by: java.net.SocketTimeoutException: Receive timed out 
at java.net.PlainDatagramSocketImpl.receive0(Native Method) 
at java.net.PlainDatagramSocketImpl.receive(Unknown Source) 
at java.net.DatagramSocket.receive(Unknown Source) 
at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1038) 

原因是,Jboss Naming Service 没有运行(netstat -an doesn't show any result for port 1099) 。我没有为命名服务配置任何特定设置。我让它采用默认端口 1099。

我是否缺少任何配置?请帮助我运行 Jboss 命名服务。

规格 :

Jboss:AS 7.1.1 最终 JRE:1.6 操作系统:Windows 7

4

1 回答 1

2

似乎您将 Jboss 版本与手动版本混合在一起。AS7 不使用 jnp,jndi 端口为 4447。

因此在standalone-full.xml 中进行了以下设置

 <security-enabled>false</security-enabled>
 ...
 <jms-destinations>
      <jms-queue name="testQueue">
           <entry name="queue/test"/>
            <entry name="java:jboss/exported/jms/queue/test"/>
      </jms-queue>
  </jms-destinations>

我能够与客户端连接,代码如下:

 Connection connection = null;
 InitialContext initialContext = null;
 Properties props = new Properties();
 props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
 props.put(Context.PROVIDER_URL, "remote://localhost:4447");
 props.put(Context.SECURITY_PRINCIPAL, "appuser");
 props.put(Context.SECURITY_CREDENTIALS, "password");

 try {
    // Step 1. Create an initial context to perform the JNDI lookup.
    initialContext = new InitialContext(props);

    // Step 2. Perfom a lookup on the queue
    Queue queue = (Queue)initialContext.lookup("jms/queue/test");

    // Step 3. Perform a lookup on the Connection Factory
    ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("jms/RemoteConnectionFactory");

    // Step 4.Create a JMS Connection
    connection = cf.createConnection();
于 2013-08-25T22:30:15.630 回答