我正在尝试使用Jboss为JMS编写示例程序。我通过以下链接了解如何使用Jboss for 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没有显示端口1099的任何结果)。 我没有为命名服务配置任何特定设置。我让它采取默认端口1099.
我错过了任何配置吗?请帮助我运行Jboss命名服务。
规格:
Jboss:AS 7.1.1决赛 JRE:1.6 操作系统:Windows 7
答案 0 :(得分: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();