远程Glassfish JMS查找

远程Glassfish JMS查找,glassfish,jms,Glassfish,Jms,我想连接到我的Glassfish服务器XX.XX.XX.XX:XXXX,它运行在我们服务器上的ubuntu机器上 我想发送消息,然后再接收它们 我的接收器看起来像这样: public JMS_Topic_Receiver(){ init(); } public List<TextMessage> getCurrentMessages() { return _currentMessages; } private void init(){ env.put("

我想连接到我的Glassfish服务器XX.XX.XX.XX:XXXX,它运行在我们服务器上的ubuntu机器上

我想发送消息,然后再接收它们

我的接收器看起来像这样:

    public JMS_Topic_Receiver(){
    init();
}

public List<TextMessage> getCurrentMessages() { return _currentMessages; }

private void init(){

    env.put("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
    env.put("org.omg.CORBA.ORBInitialHost", "10.10.32.14"); 
    env.put("org.omg.CORBA.ORBInitialPort", "8080"); 

    try {
        ctx = new InitialContext(env); // NamingException
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

public void subscribeTopic(String topicName, String userCredentials) {
    try {
        TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) ctx.lookup("myTopicConnectionFactory");
        TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(); 
        try {
            String temp = InetAddress.getLocalHost().getHostName();
            topicConnection.setClientID(temp);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = (Topic) ctx.lookup(topicName); 

        topicConnection.start();

        TopicSubscriber topicSubscriber = topicSession.createDurableSubscriber(topic, userCredentials); 
        topicSubscriber.setMessageListener(new MyMessageListener());


    }
    catch(NamingException | JMSException ex)
    {
        ex.printStackTrace();
    }
}
public JMS_Topic_Sender(){
    init();
}

private void init(){

    env.put("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
    env.put("org.omg.CORBA.ORBHost","10.10.32.14"); 
    env.put("org.omg.CORBA.ORBPort","8080");    

    try {
        ctx = new InitialContext(env);
    } catch (NamingException e) {
        e.printStackTrace();
    }
}

public void sendMessage(String message, String topicName)  {
    try {   
        TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) ctx.lookup("myTopicConnectionFactory");

        if (topicConnectionFactory != null) {
            TopicConnection topicConnection = topicConnectionFactory.createTopicConnection();

            TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 
            Topic topic = (Topic) ctx.lookup(topicName); 
            topicConnection.start(); 
            TopicPublisher topicPublisher = topicSession.createPublisher(topic);
            TextMessage tm = topicSession.createTextMessage(message);
            topicPublisher.send(tm);

            topicSession.close();
            topicConnection.stop();
            topicConnection.close();    
        }
    } catch (NamingException e) { 
        e.printStackTrace(); 
    } catch (JMSException e) {
        e.printStackTrace();
    }

}
我从各种在线教程中获得了大部分代码。 现在,当我想进行查找时。->ctx.lookup(“myTopicConnectionFactory”)

我会抛出各种各样的错误:

信息:HH000397:使用ASTQueryTranslatorFactory org.omg.CORBA.COMM_故障:FEIN:00410008:连接中止vmcid:omg次要代码:8已完成:可能

javax.naming.NamingException:在SerialContext中查找“myTopicConnectionFactory”失败

我的问题是,如何正确查找? 我猜我的财产(环境)不正确,我需要换房子,但我不知道换什么

此外,如果我在自己的计算机localhost上本地运行Glassfish,它也可以工作。 当im使用本地主机作为地址,8080作为端口时