搜尋

首頁  >  問答  >  主體

java - jms Could not connect to broker URL: tcp://localhost:61616.

看jms消息服务 代码如下
报错的地方是 QueueConnection qcConnection = qFactory.createQueueConnection();
jodi的配置是 :

java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=tcp://loclhost:61616
java.naming.security.principal=system
java.naming.cesurity.credentials=manager

#connectionFactoryNames=QueueCF
topic.topic1 = jms.topic1

connectionFactoryNames = QueueCF
queue.LoanRequestQ = jms.LoanRequestQ
queue.LoanResponseQ = jms.LoanResponseQ

代码如下 :



package chapter4.p2p;

import java.util.Enumeration;

import javax.jms.ConnectionMetaData;
import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/*
 * 获取 jndi中的元数据
 */
public class MetaData {
    public static void main(String[] args) {
        try {
            Context context = new InitialContext();
            QueueConnectionFactory qFactory  = (QueueConnectionFactory) context.lookup("QueueCF");
            System.out.println(qFactory);
            
            // createQueueConnection() 报了 Could not connect to broker URL: tcp://10.183.47.191:61616. Reason: java.net.ConnectException: Connection refused
            QueueConnection qcConnection  = qFactory.createQueueConnection();
            qcConnection.start();
            
            ConnectionMetaData metaData = qcConnection.getMetaData();
            System.out.println("jms version " + metaData.getJMSMajorVersion()+"."+metaData.getJMSMinorVersion());
            System.out.println("jms provider " + metaData.getJMSProviderName());
            System.out.println("jmsx properties supported :");
            Enumeration e = metaData.getJMSXPropertyNames();
            while (e.hasMoreElements()) {
                System.out.println(" " + e.nextElement());
            }
        } catch (NamingException e) {
            
            e.printStackTrace();
        } catch (JMSException e) {
            e.printStackTrace();
            System.exit(1);
        }
        
    }
}

百度l mac下擦找端口 lsof -i tcp:61616 但是一直没显示信息 ,请问这个是什么问题呢 ?是端口占用还是jndi的配置不对 ?

伊谢尔伦伊谢尔伦2813 天前862

全部回覆(0)我來回復

無回覆
  • 取消回覆