我是IBM MQ的新手用户。基本上我想在Client(Eclipse Paho)和IBM MQ Queue Manager之间建立连接。
我已执行以下步骤:
在客户方:
Followinig是该计划。
import java.util.logging.Logger;
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
public class MQMTTFactory {
private static Logger log = Logger.getLogger(MQMTTFactory.class.getName());
private MQMTTFactory() {
}
static final String BROKER_URL = "tcp://<<Ipaddress>>:1234";
static final String M2MIO_DOMAIN = "<Insert m2m.io domain here>";
static final String M2MIO_STUFF = "things";
static final String M2MIO_USERNAME = "Guest";
static final String M2MIO_PASSWORD_MD5 = "<m2m.io password (MD5 sum of password)>";
static MqttClient myClient = null;
public static MqttClient getMqttClient() {
MqttConnectOptions connOpt;
if (myClient == null) {
connOpt = new MqttConnectOptions();
connOpt.setCleanSession(true);
connOpt.setKeepAliveInterval(3000);
connOpt.setUserName(M2MIO_USERNAME);
// connOpt.setPassword(M2MIO_PASSWORD_MD5.toCharArray());
// Connect to Broker
try {
myClient = new MqttClient(BROKER_URL,
MqttAsyncClient.generateClientId(), new MemoryPersistence());
myClient.connect(connOpt);
} catch (MqttException e) {
log.severe("Client connection to the MQTT Broker is failed");
e.printStackTrace();
System.exit(-1);
}
}
return myClient;
}
}
但上述程序无法与服务器建立连接。 以下是运行上述程序时的错误。
Unable to connect to server (32103) - java.net.ConnectException: Connection refused: connect
任何人都可以告诉我可能出错了吗?或任何建议。
答案 0 :(得分:0)
Eclipse Paho客户端仅适用于MQTT协议。这是一个基于主题的pub / sub协议,不支持消息队列。
虽然IBM-MQ可以支持MQTT,但默认情况下不启用它。
我建议你阅读以下2篇文章以便更好地理解