2014-09-22 50 views
1

我想從Jboss 4.2.3GA實例發送JMS消息(遠程)到Jboss 7.1.1.Final實例。當我嘗試做 「7.1.1式」從Jboss 4.2.3GA發送JMS到7.1.1

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
properties.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447"); 
InitialContext jndiContext = new InitialContext(properties); 
ConnectionFactory cf = (ConnectionFactory) jndiContext.lookup("jms/RemoteConnectionFactory"); 

ClassNotFoundException的:org.jboss.naming.remote.client.InitialContextFactory

當我嘗試做 「4.2.3」 的方式

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 
properties.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447"); 
InitialContext jndiContext = new InitialContext(properties); 
ConnectionFactory cf = (ConnectionFactory) jndiContext.lookup("jms/RemoteConnectionFactory"); 

的UnknownHostException:遠程

隨着不同的地址(JNP://127.0.0.1:4447)我有java.io.StreamCorruptedException: invalid stream header: 0000000C

我開始了與7.1.1 standalone.bat --server-config=standalone-full.xml -b 0.0.0.0。 請幫忙,因爲我在這裏蒙着雙眼。任何關於如何從4.2.3GA發送JMS到7.1.1的示例都將不勝感激。

回答

0

這個問題的主要問題奠定了一個事實,即

在以前的JBoss版本中使用的舊JNP基於JNDI的實現不再支持

我們必須使用remote:協議。有用的資源是jboss dev guide JNDImaster the jboss ejb tutorial

他們告訴你,你需要jboss-client.jar%JBOSS_HOME%/bin/client。 Java SE項目確實如此。使用不同的應用程序服務器會導致一些javax.*衝突,導致注入點失敗。我結束了罐子的這一套了:

  • 的jboss-遠程-3.2.3.GA.jar
  • 的jboss-遠程命名-1.0.2.Final.jar
  • 的jboss-sasl- 1.0.0.Final.jar
  • 的jboss-編組,1.3.11.GA.jar
  • 的jboss-編組河 - 1.3.11.GA.jar
  • jboss-logging-3.1.0.GA。罐子
  • netty-3.2.6.Final.jar
  • xnio-API-3.0.3.GA.jar
  • xnio-NIO-3.0.3.GA.jar
  • HornetQ的核 - 客戶2.2.13.Final.jar
  • 將hornetq-JMS-客戶-2.2.13.Final.jar

併成功發送消息給Jboss 7.1。1個測試題目:

final Properties env = new Properties(); 
env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName()); 
env.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447"); 
InitialContext jndiContext = new InitialContext(env); 
ConnectionFactory cf = (ConnectionFactory) jndiContext.lookup("jms/RemoteConnectionFactory"); 
Topic topic = (Topic) jndiContext.lookup("jms/topic/test"); 
Connection conn = null; 
try { 
    conn = cf.createConnection(); 
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 
    MessageProducer producer = session.createProducer(topic); 
    TextMessage message = session.createTextMessage("Hello world"); 
    producer.send(message); 
} catch (JMSException e) { 
    log.error(e); 
} finally { 
    if (conn != null) { 
     try { 
      conn.close(); 
     } catch (JMSException e) { 
      log.error(e); 
     } 
    } 
} 

但是我過了關的安全,因爲

javax.security.sasl.SaslException:驗證失敗:所有可用的認證機制未能

我沒不知道如何認證。我用add-user腳本添加用戶,並使用不同的屬性玩,但沒有成功。您可以通過從該部拆卸security-realm="ApplicationRealm"standalone-full.xml

<subsystem xmlns="urn:jboss:domain:remoting:1.1"> 
    <connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/> 
</subsystem> 

和deselectiong檔案關閉安全>信息>信息提供>啓用安全?在Jboss服務器管理控制檯中。

UPDATE 禁用安全性不是必需的。使用此選項:

env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); 
env.put(Context.SECURITY_PRINCIPAL, "username"); 
env.put(Context.SECURITY_CREDENTIALS, "pass");