當前位置: 首頁>>代碼示例>>Java>>正文


Java MqttClient.generateClientId方法代碼示例

本文整理匯總了Java中org.eclipse.paho.client.mqttv3.MqttClient.generateClientId方法的典型用法代碼示例。如果您正苦於以下問題:Java MqttClient.generateClientId方法的具體用法?Java MqttClient.generateClientId怎麽用?Java MqttClient.generateClientId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.paho.client.mqttv3.MqttClient的用法示例。


在下文中一共展示了MqttClient.generateClientId方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: MqttClientKetiSub

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public MqttClientKetiSub(String serverUrl, String aeId) {
	
	this.mqttServerUrl = serverUrl;
	this.aeId = aeId;
	this.mqttClientId = MqttClient.generateClientId()+"K";
	
	System.out.println("[KETI MQTT Client] Client Initialize");
	
	try {
		mqc = new MqttClient(mqttServerUrl, mqttClientId, persistence);
		
		while(!mqc.isConnected()){
			mqc.connect();
			System.out.println("[KETI MQTT Client] Connection try");
		}
		
		System.out.println("[KETI MQTT Client] Connected to Server - " + mqttServerUrl);
	} catch (MqttException e) {
		e.printStackTrace();
	}
}
 
開發者ID:IoTKETI,項目名稱:nCube-Thyme-Java,代碼行數:22,代碼來源:MqttClientKetiSub.java

示例2: MqttClientKetiPub

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public MqttClientKetiPub(String serverUrl, String aeId) {
	
	this.mqttServerUrl = serverUrl;
	this.aeId = aeId;
	this.mqttClientId = MqttClient.generateClientId()+"K";
	
	System.out.println("[KETI MQTT Client] Client Initialize");
	
	try {
		mqc = new MqttClient(mqttServerUrl, mqttClientId, persistence);
		
		while(!mqc.isConnected()){
			mqc.connect();
			System.out.println("[KETI MQTT Client] Connection try");
		}
		
		System.out.println("[KETI MQTT Client] Connected to Server - " + mqttServerUrl);
	} catch (MqttException e) {
		e.printStackTrace();
	}
}
 
開發者ID:IoTKETI,項目名稱:nCube-Thyme-Java,代碼行數:22,代碼來源:MqttClientKetiPub.java

示例3: testMQtt

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
@Test
public void testMQtt() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    MqttClient client = new MqttClient("tcp://localhost:" + MQTT_PORT, MqttClient.generateClientId(), new MemoryPersistence());
    client.connect();
    MqttComponent mqtt = new MqttComponent();
    mqtt.client = client;
    Publisher<byte[]> fromTopic = mqtt.from("input", byte[].class);
    Subscriber<byte[]> toTopic = mqtt.to("output", byte[].class);
    Flux.from(fromTopic)
        .log()
        .subscribe(toTopic);
    
    client.subscribe("output", (topic, message) -> {
        result = new Integer(new String(message.getPayload()));
        latch.countDown();
    });
    client.publish("input", new MqttMessage(new Integer(2).toString().getBytes()));
    client.publish("input", new MqttMessage(new Integer(2).toString().getBytes()));
    latch.await(100, TimeUnit.SECONDS);
    Assert.assertEquals(2, result, 0.1);
    client.disconnect();
    client.close();
}
 
開發者ID:cschneider,項目名稱:reactive-components,代碼行數:25,代碼來源:MqttTest.java

示例4: ProtobufMqttProtocolHandler

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public ProtobufMqttProtocolHandler(NativeDeviceFactoryInterface deviceFactory) {
	super(deviceFactory);

	String mqtt_url = PropertyUtil.getProperty(MQTT_URL_PROP, null);
	if (mqtt_url == null) {
		throw new RuntimeIOException("Property '" + MQTT_URL_PROP + "' must be set");
	}

	try {
		mqttClient = new MqttClient(mqtt_url, MqttClient.generateClientId(), new MemoryPersistence());
		mqttClient.setCallback(this);
		MqttConnectOptions con_opts = new MqttConnectOptions();
		con_opts.setAutomaticReconnect(true);
		con_opts.setCleanSession(true);
		mqttClient.connect(con_opts);
		Logger.debug("Connected to {}", mqtt_url);

		// Subscribe
		Logger.debug("Subscribing to response and notification topics...");
		mqttClient.subscribe(MqttProviderConstants.RESPONSE_TOPIC);
		mqttClient.subscribe(MqttProviderConstants.GPIO_NOTIFICATION_TOPIC);
		Logger.debug("Subscribed");
	} catch (MqttException e) {
		throw new RuntimeIOException(e);
	}
}
 
開發者ID:mattjlewis,項目名稱:diozero,代碼行數:27,代碼來源:ProtobufMqttProtocolHandler.java

示例5: MqttTestClient

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public MqttTestClient(String mqttUrl) throws MqttException {
	mqttClient = new MqttClient(mqttUrl, MqttClient.generateClientId(), new MemoryPersistence());
	mqttClient.setCallback(this);
	MqttConnectOptions con_opts = new MqttConnectOptions();
	con_opts.setAutomaticReconnect(true);
	con_opts.setCleanSession(true);
	mqttClient.connect(con_opts);
	Logger.debug("Connected to {}", mqttUrl);

	lock = new ReentrantLock();
	conditions = new HashMap<>();
	responses = new HashMap<>();

	// Subscribe
	Logger.debug("Subscribing to {}...", MqttProviderConstants.RESPONSE_TOPIC);
	mqttClient.subscribe(MqttProviderConstants.RESPONSE_TOPIC);
	Logger.debug("Subscribed");
}
 
開發者ID:mattjlewis,項目名稱:diozero,代碼行數:19,代碼來源:MqttTestClient.java

示例6: InputPinHandler

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public InputPinHandler() {
  MqttConnectOptions connOpts = new MqttConnectOptions();
  connOpts.setCleanSession(true);
  try {
    mClient = new MqttClient(PropertyUtil.getMqttAddress(), MqttClient.generateClientId(), new MemoryPersistence());
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Connecting to broker " + PropertyUtil.getMqttAddress() + "...");
    }
    mClient.connect(connOpts);
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Connected to broker " + PropertyUtil.getMqttAddress() + ".");
    }
  } catch (MqttException e) {
    LOGGER.error(e.getMessage(), e);
  }
}
 
開發者ID:thilankam,項目名稱:AppInventorRaspberryPiCompanion,代碼行數:17,代碼來源:InputPinHandler.java

示例7: MQTTconect

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public MQTTconect(Context contexto,MqttCallback mqttcallback) {

        //gera um código randômico que serve como identificação do cliente
        clientID = MqttClient.generateClientId()+"circularUFPAapp";
        //cria um objeto MQTTClient android entregando como parametro o endereço o servidor e o id do cliente
        mqttAndroidClient = new MqttAndroidClient(contexto, serverAndress, clientID);
        //configura um objeto CallBack (objeto de chamada caso haja alteração)
        mqttAndroidClient.setCallback(mqttcallback);


    }
 
開發者ID:lasseufpa,項目名稱:circular,代碼行數:12,代碼來源:MQTTconect.java

示例8: MqttListener

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public MqttListener() {
	try {
		mqttClient = new MqttClient(mqttServer, MqttClient.generateClientId(), new MemoryPersistence());
		mqttClient.setCallback(this);
		MqttConnectOptions con_opts = new MqttConnectOptions();
		con_opts.setCleanSession(true);
		mqttClient.connect(con_opts);
		System.out.println("Connected to '" + mqttServer + "'");
	} catch (MqttException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:mattjlewis,項目名稱:diozero,代碼行數:14,代碼來源:MqttListener.java

示例9: MqttConnector

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
/**
 * Create a new connector.
 * 
 * @param config connector configuration.
 */
public MqttConnector(Supplier<MqttConfig> config) {
    this.configFn = config;
    
    String cid = configFn.get().getClientId();
    if (cid == null)
        cid = MqttClient.generateClientId();
    clientId = cid;
}
 
開發者ID:quarks-edge,項目名稱:quarks,代碼行數:14,代碼來源:MqttConnector.java

示例10: Server

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public Server() {

    initializeIdentifier();
    displayIdentifier();

    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("RaspberryPiServer-%d").setDaemon(true)
        .build();

    executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE, threadFactory);

    try {

      MqttConnectOptions connOpts = new MqttConnectOptions();
      connOpts.setCleanSession(true);
      mClient = new MqttClient(PropertyUtil.getMqttAddress(), MqttClient.generateClientId(), new MemoryPersistence());
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Connecting to broker " + PropertyUtil.getMqttAddress() + "...");
      }
      mClient.connect(connOpts);
      mClient.setCallback(this);
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Connected to broker " + PropertyUtil.getMqttAddress() + ".");
      }
    } catch (MqttException e) {
      e.printStackTrace();
    }

    subscribeToInternalTopic();

  }
 
開發者ID:thilankam,項目名稱:AppInventorRaspberryPiCompanion,代碼行數:31,代碼來源:Server.java

示例11: activate

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
@Activate
public void activate(MqttConfig config) throws MqttException {
    client = new MqttClient(config.serverUrl(), MqttClient.generateClientId(),
                            new MemoryPersistence());
    client.connect();
}
 
開發者ID:cschneider,項目名稱:reactive-components,代碼行數:7,代碼來源:MqttComponent.java

示例12: createMqttClient

import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public void createMqttClient(String serverAddress)
{
    String mqttClientId = MqttClient.generateClientId();
    System.out.println("Server address: " + serverAddress);
    myMQTTclient = new MqttAndroidClient(this.getApplicationContext(), serverAddress, mqttClientId);
}
 
開發者ID:jpmeijers,項目名稱:ttnmapperandroid,代碼行數:7,代碼來源:MyApp.java


注:本文中的org.eclipse.paho.client.mqttv3.MqttClient.generateClientId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。