本文整理汇总了Java中org.fusesource.mqtt.client.MQTT.setPassword方法的典型用法代码示例。如果您正苦于以下问题:Java MQTT.setPassword方法的具体用法?Java MQTT.setPassword怎么用?Java MQTT.setPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fusesource.mqtt.client.MQTT
的用法示例。
在下文中一共展示了MQTT.setPassword方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newClient
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private MQTT newClient(MqttLinkConfig config) {
MQTT client = new MQTT();
client.setClientId(config.getClientId());
client.setHost(URIs.newURI(connectionPrefix(config) + "://"
+ config.getHost() + ":" + config.getPort()));
String user = config.getUser();
if (!Strings.nullOrEmpty(user)) {
client.setUserName(user);
}
String password = config.getPassword();
if (!Strings.nullOrEmpty(password)) {
client.setPassword(password);
}
return client;
}
示例2: testConnection
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@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();
}
}
}
示例3: testConnectionWithNullPassword
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@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();
}
}
}
示例4: testConnectWithLargePassword
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@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();
}
}
}
示例5: connect
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
public void connect() {
MQTT mqtt = new MQTT();
try {
mqtt.setHost(connectionInfo.getBiobrightUrl());
mqtt.setUserName(connectionInfo.getBiobrightUserName());
mqtt.setPassword(connectionInfo.getBiobrightPassword());
// TODO change security policy that is actually disabled with this code.
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
mqtt.setSslContext(sslContext);
logger.info("Opening MQTT socket.. ");
connection = mqtt.blockingConnection();
logger.info("Opened MQTT socket, connecting.. ");
connection.connect();
logger.info("Connected MQTT socket.. ");
} catch (Exception e) {
logger.error("connect()", e);
if(connection != null) {
connection = null;
}
throw new RuntimeException("Connection failed.", e);
}
}
示例6: setup
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@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);
}
}
示例7: retrieveMQTTConnection
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private static BlockingConnection retrieveMQTTConnection(String host) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setHost(host);
mqtt.setUserName("admin");
mqtt.setPassword("admin");
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
return connection;
}
示例8: testDeployment
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Test
public void testDeployment() throws Exception {
BlockingConnection publishConnection = null;
BlockingConnection subscribeConnection = null;
try {
Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
MQTT mqtt = new MQTT();
mqtt.setUserName(USER_NAME);
mqtt.setPassword(PASSWORD);
subscribeConnection = mqtt.blockingConnection();
subscribeConnection.connect();
subscribeConnection.subscribe(new Topic[]{outputTopic});
publishConnection = mqtt.blockingConnection();
publishConnection.connect();
publishConnection.publish(TOPIC_INPUT, MESSAGE_INPUT.getBytes(), QoS.AT_LEAST_ONCE, false);
Message message = subscribeConnection.receive(1000, TimeUnit.MILLISECONDS);
Assert.assertNotNull("No output message from " + TOPIC_OUTPUT, message);
Assert.assertEquals(MESSAGE_OUTPUT, new String(message.getPayload()));
Assert.assertNull("More than one message received from " + TOPIC_OUTPUT,
subscribeConnection.receive(1000, TimeUnit.MILLISECONDS));
} finally {
if (publishConnection != null) {
publishConnection.disconnect();
}
}
}
示例9: testDeployment
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Test
public void testDeployment() throws Exception {
BlockingConnection publishConnection = null;
BlockingConnection subscribeConnection = null;
try {
Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
MQTT mqtt = new MQTT();
mqtt.setUserName(USER_NAME);
mqtt.setPassword(PASSWORD);
subscribeConnection = mqtt.blockingConnection();
subscribeConnection.connect();
subscribeConnection.subscribe(new Topic[]{outputTopic});
publishConnection = mqtt.blockingConnection();
publishConnection.connect();
publishConnection.publish(TOPIC_INPUT, MESSAGE_INPUT.getBytes(), QoS.AT_LEAST_ONCE, false);
Message message = subscribeConnection.receive(1000, TimeUnit.MILLISECONDS);
Assert.assertNotNull("No output message from " + TOPIC_OUTPUT, message);
Assert.assertEquals(MESSAGE_OUTPUT, new String(message.getPayload()));
Assert.assertNull("More than one message received from " + TOPIC_OUTPUT,
subscribeConnection.receive(1000, TimeUnit.MILLISECONDS));
} finally {
if (publishConnection != null && publishConnection.isConnected()) {
publishConnection.disconnect();
}
if (subscribeConnection != null && subscribeConnection.isConnected()) {
subscribeConnection.disconnect();
}
}
}
示例10: main
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
/**
* Only execution point for this application.
* @param args command line args.
* @throws Exception if something goes wrong.
*/
public static void main(final String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(MESSAGE_PAYLOAD)));
String payload = reader.readLine();
reader.close();
BlockingConnection publishConnection = null;
BlockingConnection subscribeConnection = null;
try {
Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
MQTT mqtt = new MQTT();
mqtt.setUserName(USER_NAME);
mqtt.setPassword(PASSWORD);
subscribeConnection = mqtt.blockingConnection();
subscribeConnection.connect();
subscribeConnection.subscribe(new Topic[]{outputTopic});
publishConnection = mqtt.blockingConnection();
publishConnection.connect();
publishConnection.publish(TOPIC_INPUT, payload.getBytes(), QoS.AT_LEAST_ONCE, false);
System.out.println("Published a message to " + TOPIC_INPUT + ": " + payload);
Message msg = subscribeConnection.receive(60000, TimeUnit.MILLISECONDS);
if (msg != null) {
System.out.println("Received a message from " + TOPIC_OUTPUT + ": " + new String(msg.getPayload()));
} else {
System.out.println("No message was received from " + TOPIC_OUTPUT);
}
} finally {
if (publishConnection != null && publishConnection.isConnected()) {
publishConnection.disconnect();
}
if (subscribeConnection != null && subscribeConnection.isConnected()) {
subscribeConnection.disconnect();
}
Dispatch.shutdown();
}
}
示例11: provideMqttConnection
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Provides
@Singleton
public CallbackConnection provideMqttConnection(final MQTTProperties mqttProperties) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setHost(mqttProperties.getBrokerHost(), mqttProperties.getBrokerPort());
mqtt.setCleanSession(mqttProperties.isMqttcleanSession());
mqtt.setClientId(mqttProperties.getMqttClientId());
mqtt.setKeepAlive((short) mqttProperties.getMqttKeepAlive());
mqtt.setUserName(mqttProperties.getMqttUsername());
mqtt.setPassword(mqttProperties.getMqttPassword());
return mqtt.callbackConnection();
}
示例12: main
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String user = env("ACTIVEMQ_USER", "admin");
String password = env("ACTIVEMQ_PASSWORD", "password");
String host = env("ACTIVEMQ_HOST", "localhost");
int port = Integer.parseInt(env("ACTIVEMQ_PORT", "1883"));
final String destination = arg(args, 0, "/topic/event");
int messages = 10000;
int size = 256;
String DATA = "abcdefghijklmnopqrstuvwxyz";
String body = "";
for (int i = 0; i < size; i++) {
body += DATA.charAt(i % DATA.length());
}
Buffer msg = new AsciiBuffer(body);
MQTT mqtt = new MQTT();
mqtt.setHost(host, port);
mqtt.setUserName(user);
mqtt.setPassword(password);
FutureConnection connection = mqtt.futureConnection();
connection.connect().await();
final LinkedList<Future<Void>> queue = new LinkedList<Future<Void>>();
UTF8Buffer topic = new UTF8Buffer(destination);
for (int i = 1; i <= messages; i++) {
// Send the publish without waiting for it to complete. This allows
// us
// to send multiple message without blocking..
queue.add(connection.publish(topic, msg, QoS.AT_LEAST_ONCE, false));
// Eventually we start waiting for old publish futures to complete
// so that we don't create a large in memory buffer of outgoing
// message.s
if (queue.size() >= 1000) {
queue.removeFirst().await();
}
if (i % 1000 == 0) {
System.out.println(String.format("Sent %d messages.", i));
}
}
queue.add(connection.publish(topic, new AsciiBuffer("SHUTDOWN"), QoS.AT_LEAST_ONCE, false));
while (!queue.isEmpty()) {
queue.removeFirst().await();
}
connection.disconnect().await();
System.exit(0);
}
示例13: activate
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Override
public void activate(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());
}
if (mqttClientConfig.getWillTopic() != null) {
client.setWillTopic(mqttClientConfig.getWillTopic());
}
initializeConnection();
thread = new Thread(new Runnable()
{
@Override
public void run()
{
while (true) {
try {
Message msg = connection.receive();
holdingBuffer.add(msg);
} catch (Exception ex) {
LOG.error("Trouble receiving", ex);
}
}
}
});
thread.start();
} catch (Exception ex) {
LOG.error("Caught exception during activation: ", ex);
throw new RuntimeException(ex);
}
}
示例14: main
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
public static void main(String []args) throws Exception {
String user = env("ACTIVEMQ_USER", "admin");
String password = env("ACTIVEMQ_PASSWORD", "password");
String host = env("ACTIVEMQ_HOST", "localhost");
int port = Integer.parseInt(env("ACTIVEMQ_PORT", "1883"));
final String destination = arg(args, 0, "/topic/event");
int messages = 10000;
int size = 256;
String DATA = "abcdefghijklmnopqrstuvwxyz";
String body = "";
for( int i=0; i < size; i ++) {
body += DATA.charAt(i%DATA.length());
}
Buffer msg = new AsciiBuffer(body);
MQTT mqtt = new MQTT();
mqtt.setHost(host, port);
mqtt.setUserName(user);
mqtt.setPassword(password);
FutureConnection connection = mqtt.futureConnection();
connection.connect().await();
final LinkedList<Future<Void>> queue = new LinkedList<Future<Void>>();
UTF8Buffer topic = new UTF8Buffer(destination);
for( int i=1; i <= messages; i ++) {
// Send the publish without waiting for it to complete. This allows us
// to send multiple message without blocking..
queue.add(connection.publish(topic, msg, QoS.AT_LEAST_ONCE, false));
// Eventually we start waiting for old publish futures to complete
// so that we don't create a large in memory buffer of outgoing message.s
if( queue.size() >= 1000 ) {
queue.removeFirst().await();
}
if( i % 1000 == 0 ) {
System.out.println(String.format("Sent %d messages.", i));
}
}
queue.add(connection.publish(topic, new AsciiBuffer("SHUTDOWN"), QoS.AT_LEAST_ONCE, false));
while( !queue.isEmpty() ) {
queue.removeFirst().await();
}
connection.disconnect().await();
System.exit(0);
}