本文整理了Java中org.fusesource.mqtt.client.MQTT.<init>()
方法的一些代码示例,展示了MQTT.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MQTT.<init>()
方法的具体详情如下:
包路径:org.fusesource.mqtt.client.MQTT
类名称:MQTT
方法名:<init>
暂无
代码示例来源:origin: fusesource/mqtt-client
public CallbackConnection callbackConnection() {
if( !isCleanSession() && ( getClientId()==null || getClientId().length==0 )) {
throw new IllegalArgumentException("The client id MUST be configured when clean session is set to false");
}
return new CallbackConnection(new MQTT(this));
}
public FutureConnection futureConnection() {
代码示例来源:origin: apache/storm
/**
* Initializes {@code connection}.
* @throws Exception if an exception during connecting to connector occurs
*/
public static void startPublisher() throws Exception {
MQTT client = new MQTT();
client.setTracer(new MqttLogger());
client.setHost("tcp://localhost:1883");
client.setClientId("MqttBrokerPublisher");
connection = client.blockingConnection();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
LOG.info("Shutting down MQTT client...");
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
});
connection.connect();
}
代码示例来源:origin: andsel/moquette
@Before
public void setUp() throws Exception {
startServer();
m_mqtt = new MQTT();
m_mqtt.setHost("localhost", 1883);
}
代码示例来源:origin: apache/storm
public static MQTT configureClient(MqttOptions options, String clientId, KeyStoreLoader keyStoreLoader)
throws Exception {
MQTT client = new MQTT();
URI uri = URI.create(options.getUrl());
代码示例来源:origin: andsel/moquette
String willTestamentMsg = "Bye bye";
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
mqtt.setClientId("WillTestamentPublisher");
代码示例来源:origin: org.fusesource.mqtt-client/mqtt-client
public CallbackConnection callbackConnection() {
if( !isCleanSession() && ( getClientId()==null || getClientId().length==0 )) {
throw new IllegalArgumentException("The client id MUST be configured when clean session is set to false");
}
return new CallbackConnection(new MQTT(this));
}
public FutureConnection futureConnection() {
代码示例来源:origin: tuanhiep/mqtt-jmeter
private FutureConnection createConnection(String host,String clientId) {
try {
MQTT client = new MQTT();
client.setHost(host);
client.setClientId(clientId);
return client.futureConnection();
} catch (URISyntaxException e) {
getLogger().error(e.getMessage());
return null;
}
}
private FutureConnection createConnection(String host,String clientId,String user, String password) {
代码示例来源: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: tuanhiep/mqtt-jmeter
private CallbackConnection createConnection(String host, String clientId,
boolean durable) throws URISyntaxException {
MQTT client = new MQTT();
client.setHost(host);
client.setClientId(clientId);
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: 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: stackoverflow.com
try{
MqttMessage message2 = new MqttMessage();
MQTT mqtt_connect = new MQTT();
mqtt_connect.setHost(Host_Address, Integer.parseInt(port));
String topic = "/call/MQTT_Config";
mqtt_connect.setClientId("MQTT_Config");
mqtt_connect.setWillRetain(false);
mqtt_connect.isWillRetain();
mqtt_connect.setWillTopic(topic);
BlockingConnection m_publisher = mqtt_connect.blockingConnection();
m_publisher.connect();
}
catch(Exception e){
add message for connection not established
}
代码示例来源:origin: apache/activemq-artemis
private static BlockingConnection retrieveMQTTConnection(String host) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setHost(host);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
return connection;
}
}
代码示例来源:origin: apache/activemq-artemis
private static BlockingConnection retrieveMQTTConnection(String host) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setHost(host);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
return connection;
}
代码示例来源:origin: sitewhere/sitewhere
@Override
public Void call() throws Exception {
try {
this.mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
this.connection = mqtt.blockingConnection();
connection.connect();
System.out.println("Connected to: " + mqtt.getHost());
long start = System.currentTimeMillis();
for (int i = 0; i < messageCount; i++) {
sendLocationOverMqtt();
}
System.out
.println("Sent " + messageCount + " events in " + (System.currentTimeMillis() - start) + "ms.");
connection.disconnect();
return null;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.streampipes/streampipes-connect
@Override
public void run() {
this.running = true;
MQTT mqtt = new MQTT();
try {
mqtt.setHost(broker);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
Topic[] topics = {new Topic(topic, QoS.AT_LEAST_ONCE)};
byte[] qoses = connection.subscribe(topics);
while(running && ((maxElementsToReceive == -1) || (this.messageCount <= maxElementsToReceive))) {
Message message = connection.receive();
byte[] payload = message.getPayload();
consumer.onEvent(payload);
message.ack();
this.messageCount++;
}
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: streampipes/streampipes-ce
@Override
public void run() {
this.running = true;
MQTT mqtt = new MQTT();
try {
mqtt.setHost(broker);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
Topic[] topics = {new Topic(topic, QoS.AT_LEAST_ONCE)};
byte[] qoses = connection.subscribe(topics);
while(running && ((maxElementsToReceive == -1) || (this.messageCount <= maxElementsToReceive))) {
Message message = connection.receive();
byte[] payload = message.getPayload();
consumer.onEvent(payload);
message.ack();
this.messageCount++;
}
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: apache/activemq-artemis
private MQTT createMQTTSslConnection(String clientId, boolean clean) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setConnectAttemptsMax(1);
mqtt.setReconnectAttemptsMax(0);
mqtt.setTracer(createTracer());
mqtt.setHost("ssl://localhost:" + port);
if (clientId != null) {
mqtt.setClientId(clientId);
}
mqtt.setCleanSession(clean);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(new KeyManager[0], new TrustManager[]{new DefaultTrustManager()}, new SecureRandom());
mqtt.setSslContext(ctx);
return mqtt;
}
代码示例来源:origin: apache/activemq-artemis
private MQTT createMQTTTcpConnection(String clientId, boolean clean) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setConnectAttemptsMax(1);
mqtt.setReconnectAttemptsMax(0);
mqtt.setTracer(createTracer());
mqtt.setVersion("3.1.1");
if (clientId != null) {
mqtt.setClientId(clientId);
}
mqtt.setCleanSession(clean);
mqtt.setHost("localhost", port);
return mqtt;
}
代码示例来源:origin: apache/activemq-artemis
private BlockingConnection retrieveMQTTConnection(String host, String truststorePath, String truststorePass, String keystorePath, String keystorePass) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setConnectAttemptsMax(1);
mqtt.setReconnectAttemptsMax(0);
mqtt.setHost(host);
SSLContext sslContext = new SSLSupport()
.setKeystorePath(keystorePath)
.setKeystorePassword(keystorePass)
.setTruststorePath(truststorePath)
.setTruststorePassword(truststorePass)
.createContext();
mqtt.setSslContext(sslContext);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
return connection;
}
内容来源于网络,如有侵权,请联系作者删除!