忘记说了:服务器是websphere application server 5.0

解决方案 »

  1.   

    可以调用集群中的任意一个cluster的ejb(例如127.0.1:7003)。他们会自动进行负载均衡的。
    加入系统中有127.0.0.1:7005 ,127.0.0.1:7007
    前提是,在启动的时候。要启动127.0.0.1:7003 , 127.0.0.1:7005 ,127.0.0.1:7007
    要连接的ejb 在127.0.0.1:7003上。这样使没有问题的/。
    如果这个时候 127.0.0.1:7003当掉。会自动切换到127.0.0.1:7005 ,127.0.0.1:7007上的。
      

  2.   

    刚才我说的weblogic集群中的解决方案.webshpere我没有试过.
    weblogic连接到前置机上肯定是不可以得.
      

  3.   

    能说得具体点吗?不在集群情况下,调用EJB远程接口的方法是这样的 :
    import com.test.sessionbean.cs.*;
    import javax.naming.*;
    import java.util.Hashtable;
    import javax.rmi.PortableRemoteObject;public class EJBClient extends Object
    {
      private YhsfHome yhsfHome = null;  //Construct the EJB test client
      public EJBClient()
      {
        initialize();
      }  public void initialize()
      {
        try
        {
          //get naming context
          Context context = getInitialContext();      //look up jndi name
          Object ref = context.lookup("Yhsf");
          //look up jndi name and cast to Home interface
          yhsfHome = (YhsfHome) PortableRemoteObject.narrow(ref, YhsfHome.class);
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
      }  private Context getInitialContext() throws NamingException
      {
        Hashtable environment = new Hashtable();    environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
        environment.put(Context.PROVIDER_URL, "corbaloc:iiop:10.20.2.26:2809");
        environment.put(Context.URL_PKG_PREFIXES, "com.ibm.ws.naming");    return new InitialContext(environment);
      }
     //----------------------------------------------------------------------------
      // Utility Methods
      //----------------------------------------------------------------------------  public YhsfHome getHome()
      {
        return yhsfHome;
      }可是将EJB部署在WEBSPHERE群集中后再这样调用则出现以下错误:javax.naming.ServiceUnavailableException: A communication failure occurred while attempting to obtain an initial context using the provider url: "corbaloc:iiop:10.20.2.150:2809". Make sure that the host and port information is correct and that the server identified by the provider url is a running name server.  If no port number is specified, the default port number 2809 is used. Other possible causes include the network environment or workstation network configuration.  Root exception is org.omg.CORBA.TRANSIENT: p650:host=p650,port=9900  minor code: 4942F303  completed: No   at com.ibm.CORBA.transport.TransportConnectionBase.connect(TransportConnectionBase.java:384)   at com.ibm.rmi.transport.TCPTransport.getConnection(TCPTransport.java:178)   at com.ibm.rmi.iiop.TransportManager.get(TransportManager.java:84)   at com.ibm.rmi.iiop.GIOPImpl.locate(GIOPImpl.java:177)   at com.ibm.CORBA.iiop.ClientDelegate._createRequest(ClientDelegate.java:2404)   at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1276)   at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1175)   at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1928)   at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:245)   at com.ibm.WsnBootstrap._WsnNameServiceStub.getProperties(_WsnNameServiceStub.java:37)   at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1090)   at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:676)   at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:604)   at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:478)   at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:102)   at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:408)   at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:131)   at javax.naming.InitialContext.lookup(InitialContext.java:359)   at YLFMQ.EJBClient.initialize(EJBClient.java:27)   at YLFMQ.EJBClient.<init>(EJBClient.java:16)   at YLFMQ.SolveFycx.outputString(SolveFycx.java:43)   at YLFMQ.Responder.run(Responder.java:104)   at java.lang.Thread.run(Thread.java:512)
    程序应该做怎样的改动呢?
      

  4.   

    按照WebLogic的集群说。3个cluster , A (192.168.0.1:2809),B(192.168.0.2:2089),C(192.168.0.3:2089), 一个代理机(负责负载)(192.168.0.10:2089),我们如果要调用集群中的EJB使用environment.put(Context.PROVIDER_URL, "corbaloc:iiop:192.168.0.10:2809");是连接不上的。必须使用 environment.put(Context.PROVIDER_URL, "corbaloc:iiop:192.168.0.1:2809");或192.168.0.2:2809、192.168.0.3:2809才可以的。
    但是对于webshere我就不时太清楚了,我觉得集群技术应该差不多的。你可以试一下。祝你成功 。
      

  5.   

    疑问:
    如何在代码中hardcode application server IP (192.168.0.1:2809),B(192.168.0.2:2089),C(192.168.0.3:2089),那cluster 的优势在哪里?
    那写代码是这样:
    -----------------------
    final String IP_A = "192.168.0.1:2809";
    final String IP_B = "192.168.0.2:2809";
    final String IP_C = "192.168.0.3:2809";
    Context test() {
     Contect ctx = null;  
     try{ 
       ctx = test_a(IP_A );
       return ctx;
     } catch(Exception e) {
      //do nothing; 
     }
    try{ 
       ctx = test_a(IP_B);
       return ctx;
     } catch(Exception e) {
      //do nothing; 
     }
     try{ 
       ctx = test_a(IP_C);
       return ctx;
     } catch(Exception e) {
      //do nothing; 
     }private Context test_a(String url) throws NamingException
      {
        Hashtable environment = new Hashtable();    environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
        environment.put(Context.PROVIDER_URL, url);
        environment.put(Context.URL_PKG_PREFIXES, "com.ibm.ws.naming");    return new InitialContext(environment);
      }
    ---------------------
      

  6.   

    如果真的是这样,那cluster的好处.....
    我觉得不应该是这样。
    期待高手ING
      

  7.   

    没有问题的。
    前提:启动的时候A,B,C机均启动。程序里只要连接A机就可以。本身自己回进行负载均衡的。
    假如现在A宕机,系统会自动切换到其他机器的ejb。
    你的代码
    这样就可以了。
    final String IP_A = "192.168.0.1:2809";
    Context test() {
     Contect ctx = null;  
     try{ 
       ctx = test_a(IP_A );
       return ctx;
     } catch(Exception e) {
      //do nothing; 
     }private Context test_a(String url) throws NamingException
      {
        Hashtable environment = new Hashtable();    environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
        environment.put(Context.PROVIDER_URL, url);
        environment.put(Context.URL_PKG_PREFIXES, "com.ibm.ws.naming");    return new InitialContext(environment);
      }
      

  8.   

    我问了IBM的人,他们说websphere 和weblogic的集群方式是不一样的