0

我已经实现了一个 JMS 生产者和消费者,它们部署在两个不同的主机中,都在一个 DMZ 中。 在这里,我阅读了如何为生产者定义自定义主机和端口。但我不明白我必须把那条线放在哪里。

这是我的代码:

Connection connection = null;
    try{

        System.out.println("Connecting to "+getBrokerUrl());
        connection = (new ActiveMQConnectionFactory(getBrokerUrl())).createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(this.topicName);

        TextMessage txtMsg = session.createTextMessage();
                    txtMsg.setText(msg);
                    txtMsg.setJMSType(msgType);

        MessageProducer producer = session.createProducer(topic);
                        producer.send(txtMsg);

    }
    catch(Exception e){
        System.out.println("Error: " + e.getMessage());
    }
    finally{
        try{
            connection.close();
        }
        catch(JMSException je){
            System.out.println("Unable to close connection: "+je.getMessage());
        }
    }

谁能帮我?

4

1 回答 1

0

应该在您传递 getBrokerUrl() 结果的 ActiveMQConnectionFactory 实例中:

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
于 2015-05-18T10:17:02.300 回答