本文整理了Java中org.fusesource.mqtt.client.MQTT.setUserName()
方法的一些代码示例,展示了MQTT.setUserName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MQTT.setUserName()
方法的具体详情如下:
包路径:org.fusesource.mqtt.client.MQTT
类名称:MQTT
方法名:setUserName
暂无
代码示例来源:origin: fusesource/mqtt-client
public void setUserName(String userName) {
this.setUserName(utf8(userName));
}
public void setUserName(UTF8Buffer userName) {
代码示例来源:origin: fusesource/mqtt-client
main.mqtt.setClientId(shift(argl));
} else if ("-u".equals(arg)) {
main.mqtt.setUserName(shift(argl));
} else if ("-p".equals(arg)) {
main.mqtt.setPassword(shift(argl));
代码示例来源:origin: fusesource/mqtt-client
main.mqtt.setClientId(shift(argl));
} else if ("-u".equals(arg)) {
main.mqtt.setUserName(shift(argl));
} else if ("-p".equals(arg)) {
main.mqtt.setPassword(shift(argl));
代码示例来源:origin: apache/storm
client.setUserName(options.getUserName());
client.setPassword(options.getPassword());
client.setTracer(new MqttLogger());
代码示例来源:origin: org.fusesource.mqtt-client/mqtt-client
public void setUserName(String userName) {
this.setUserName(utf8(userName));
}
public void setUserName(UTF8Buffer userName) {
代码示例来源:origin: dempeZheng/forest-chat
public void init(String host, int port) throws Exception {
mqtt = new MQTT();
mqtt.setHost(host, port);
mqtt.setUserName(uid);
mqtt.setPassword(pwd);
mqtt.setClientId(uid);
}
代码示例来源:origin: eu.limetri.ygg/ygg-client
private void connect() throws Exception {
mqttClient.setHost(baseUrl.getHost(), port);
mqttClient.setTracer(new Tracer() {
@Override
public void onReceive(MQTTFrame frame) {
log.debug("receive:{}", frame);
}
@Override
public void onSend(MQTTFrame frame) {
log.debug("send:{}", frame);
}
});
mqttClient.setUserName(username);
mqttClient.setPassword(password);
connection = mqttClient.blockingConnection();
connection.connect();
}
代码示例来源:origin: com.sitewhere/sitewhere-core
mqtt.setUserName(component.getUsername());
代码示例来源:origin: tuanhiep/mqtt-jmeter
private CallbackConnection createConnection(String host, String clientId,
boolean durable, String user, String password)
throws URISyntaxException {
MQTT client = new MQTT();
client.setHost(host);
client.setClientId(clientId);
client.setUserName(user);
client.setPassword(password);
client.setCleanSession(!durable);
return client.callbackConnection();
}
代码示例来源:origin: tuanhiep/mqtt-jmeter
private FutureConnection createConnection(String host,String clientId,String user, String password) {
try {
MQTT client = new MQTT();
client.setHost(host);
client.setUserName(user);
client.setPassword(password);
client.setClientId(clientId);
return client.futureConnection();
} catch (URISyntaxException e) {
getLogger().error(e.getMessage());
return null;
}
}
代码示例来源:origin: org.eclipse.kapua/kapua-client-gateway-provider-fuse
@Override
public FuseChannel build() throws Exception {
final URI broker = Objects.requireNonNull(broker(), "Broker must be set");
final String clientId = Strings.nonEmptyText(clientId(), "clientId");
final MqttNamespace namespace = Objects.requireNonNull(namespace(), "Namespace must be set");
final BinaryPayloadCodec codec = Objects.requireNonNull(codec(), "Codec must be set");
final MQTT mqtt = new MQTT();
mqtt.setCleanSession(false);
mqtt.setHost(broker);
mqtt.setClientId(clientId);
final Object credentials = credentials();
if (credentials == null) {
// none
} else if (credentials instanceof UserAndPassword) {
final UserAndPassword userAndPassword = (UserAndPassword) credentials;
mqtt.setUserName(userAndPassword.getUsername());
mqtt.setPassword(userAndPassword.getPasswordAsString());
} else {
throw new IllegalStateException(
String.format("Unknown credentials type: %s", credentials.getClass().getName()));
}
final CallbackConnection connection = mqtt.callbackConnection();
final FuseChannel result = new FuseChannel(clientId, namespace, codec, connection);
return result;
}
}
代码示例来源:origin: eclipse/kapua
@Override
public FuseChannel build() throws Exception {
final URI broker = Objects.requireNonNull(broker(), "Broker must be set");
final String clientId = Strings.nonEmptyText(clientId(), "clientId");
final MqttNamespace namespace = Objects.requireNonNull(namespace(), "Namespace must be set");
final BinaryPayloadCodec codec = Objects.requireNonNull(codec(), "Codec must be set");
final MQTT mqtt = new MQTT();
mqtt.setCleanSession(false);
mqtt.setHost(broker);
mqtt.setClientId(clientId);
final Object credentials = credentials();
if (credentials == null) {
// none
} else if (credentials instanceof UserAndPassword) {
final UserAndPassword userAndPassword = (UserAndPassword) credentials;
mqtt.setUserName(userAndPassword.getUsername());
mqtt.setPassword(userAndPassword.getPasswordAsString());
} else {
throw new IllegalStateException(
String.format("Unknown credentials type: %s", credentials.getClass().getName()));
}
final CallbackConnection connection = mqtt.callbackConnection();
final FuseChannel result = new FuseChannel(clientId, namespace, codec, connection);
return result;
}
}
代码示例来源:origin: sitewhere/sitewhere
mqtt.setUserName(component.getUsername());
代码示例来源:origin: apache/activemq-artemis
@Test
public void testConnectWithLargePassword() throws Exception {
for (String version : Arrays.asList("3.1", "3.1.1")) {
String longString = new String(new char[65535]);
BlockingConnection connection = null;
try {
MQTT mqtt = createMQTTConnection("test-" + version, true);
mqtt.setUserName(longString);
mqtt.setPassword(longString);
mqtt.setConnectAttemptsMax(1);
mqtt.setVersion(version);
connection = mqtt.blockingConnection();
connection.connect();
BlockingConnection finalConnection = connection;
assertTrue("Should be connected", Wait.waitFor(() -> finalConnection.isConnected(), 5000, 100));
} finally {
if (connection != null && connection.isConnected()) connection.disconnect();
}
}
}
代码示例来源:origin: apache/activemq-artemis
@Test(timeout = 30000, expected = EOFException.class)
public void testConnectionWithNullPassword() throws Exception {
for (String version : Arrays.asList("3.1", "3.1.1")) {
BlockingConnection connection = null;
try {
MQTT mqtt = createMQTTConnection("test-" + version, true);
mqtt.setUserName(fullUser);
mqtt.setPassword((String) null);
mqtt.setConnectAttemptsMax(1);
mqtt.setVersion(version);
connection = mqtt.blockingConnection();
connection.connect();
fail("Connect should fail");
} finally {
if (connection != null && connection.isConnected()) connection.disconnect();
}
}
}
}
代码示例来源:origin: apache/apex-malhar
client.setUserName(mqttClientConfig.getUserName());
代码示例来源:origin: apache/activemq-artemis
@Test(timeout = 30000)
public void testConnection() throws Exception {
for (String version : Arrays.asList("3.1", "3.1.1")) {
BlockingConnection connection = null;
try {
MQTT mqtt = createMQTTConnection("test-" + version, true);
mqtt.setUserName(fullUser);
mqtt.setPassword(fullPass);
mqtt.setConnectAttemptsMax(1);
mqtt.setVersion(version);
connection = mqtt.blockingConnection();
connection.connect();
BlockingConnection finalConnection = connection;
assertTrue("Should be connected", Wait.waitFor(() -> finalConnection.isConnected(), 5000, 100));
} finally {
if (connection != null && connection.isConnected()) connection.disconnect();
}
}
}
代码示例来源:origin: org.apache.apex/malhar-contrib
client.setUserName(mqttClientConfig.getUserName());
代码示例来源:origin: apache/apex-malhar
@Override
public void setup(OperatorContext context)
{
try {
client = new MQTT();
if (mqttClientConfig.getClientId() != null) {
client.setClientId(mqttClientConfig.getClientId());
}
client.setCleanSession(mqttClientConfig.isCleanSession());
client.setConnectAttemptsMax(mqttClientConfig.getConnectAttemptsMax());
client.setHost(mqttClientConfig.getHost(), mqttClientConfig.getPort());
client.setKeepAlive(mqttClientConfig.getKeepAliveInterval());
if (mqttClientConfig.getPassword() != null) {
client.setPassword(mqttClientConfig.getPassword());
}
if (mqttClientConfig.getUserName() != null) {
client.setUserName(mqttClientConfig.getUserName());
}
if (mqttClientConfig.getWillMessage() != null) {
client.setWillMessage(mqttClientConfig.getWillMessage());
client.setWillQos(mqttClientConfig.getWillQos());
client.setWillRetain(mqttClientConfig.isWillRetain());
client.setWillTopic(mqttClientConfig.getWillTopic());
}
connection = client.blockingConnection();
connection.connect();
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: jboss-switchyard/release
Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
MQTT mqtt = new MQTT();
mqtt.setUserName(USER_NAME);
mqtt.setPassword(PASSWORD);
subscribeConnection = mqtt.blockingConnection();
内容来源于网络,如有侵权,请联系作者删除!