当前位置: 首页>>代码示例>>Java>>正文


Java MqttConnectOptions.setAutomaticReconnect方法代码示例

本文整理汇总了Java中org.eclipse.paho.client.mqttv3.MqttConnectOptions.setAutomaticReconnect方法的典型用法代码示例。如果您正苦于以下问题:Java MqttConnectOptions.setAutomaticReconnect方法的具体用法?Java MqttConnectOptions.setAutomaticReconnect怎么用?Java MqttConnectOptions.setAutomaticReconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.paho.client.mqttv3.MqttConnectOptions的用法示例。


在下文中一共展示了MqttConnectOptions.setAutomaticReconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
@Override
public void init(MqttPluginConfiguration configuration) {
  retryInterval = configuration.getRetryInterval();

  mqttClientOptions = new MqttConnectOptions();
  mqttClientOptions.setCleanSession(false);
  mqttClientOptions.setMaxInflight(configuration.getMaxInFlight());
  mqttClientOptions.setAutomaticReconnect(true);
  String clientId = configuration.getClientId();
  if (StringUtils.isEmpty(clientId)) {
    clientId = UUID.randomUUID().toString();
  }
  if (!StringUtils.isEmpty(configuration.getAccessToken())) {
    mqttClientOptions.setUserName(configuration.getAccessToken());
  }
  try {
    mqttClient = new MqttAsyncClient("tcp://" + configuration.getHost() + ":" + configuration.getPort(), clientId);
  } catch (Exception e) {
    log.error("Failed to create mqtt client", e);
    throw new RuntimeException(e);
  }
  // connect();
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:24,代码来源:MqttPlugin.java

示例2: connectAndSubscribe

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
/*********************************************************************************************************************************************************************
 *
 */
private void connectAndSubscribe() throws Exception {

  ConfigHandler configHandler = serialMqttBridge.getConfigHandler();

  mqttClient = new MqttClient(configHandler.getMqttBrokerUrl(), configHandler.getMqttClientId(), null);
  MqttConnectOptions connOpts = new MqttConnectOptions();
  connOpts.setCleanSession(true);
  connOpts.setAutomaticReconnect(true);

  // Authentication
  if (configHandler.getMqttBrokerUsername() != null && configHandler.getMqttBrokerPassword() != null) {
    connOpts.setUserName(configHandler.getMqttBrokerUsername());
    connOpts.setPassword(configHandler.getMqttBrokerPassword().toCharArray());
  }

  // MqttCallback
  mqttCallback = new MqttSubscriptionCallback(this);
  mqttClient.setCallback(mqttCallback);

  mqttClient.connect(connOpts);

  // Subscribe to defined inbound topic
  mqttClient.subscribe(configHandler.getMqttTopicSubscribe(), configHandler.getMqttQosSubscribe());
}
 
开发者ID:DerTomm,项目名称:SerialMqttBridge,代码行数:28,代码来源:MqttHandler.java

示例3: ProtobufMqttProtocolHandler

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的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

示例4: MqttTestClient

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的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

示例5: MyMqttCloudClient

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
public MyMqttCloudClient(String cloudBrokerAddress, String clientId) {
//		this._cloudTopic = cloudTopic;
		this._cloudBrokerAddress = cloudBrokerAddress;
		this._clientId = clientId;
		MemoryPersistence persistence = new MemoryPersistence();
		try {
			this._mqCloudClient = new MqttClient(this._cloudBrokerAddress,
					this._clientId, persistence);
			this._mqCloudClient.setCallback(this);
			MqttConnectOptions connOpts = new MqttConnectOptions();
//			connOpts.setCleanSession(true);
			connOpts.setConnectionTimeout(0);
			connOpts.setKeepAliveInterval(30);
			connOpts.setAutomaticReconnect(true);
			System.out.println("Connecting to cloud broker: " + this._cloudBrokerAddress);
			this._mqCloudClient.connect(connOpts);
			System.out.println("Connected");			
		} catch (MqttException me) {
			System.out.println("reason " + me.getReasonCode());
			System.out.println("msg " + me.getMessage());
			System.out.println("loc " + me.getLocalizedMessage());
			System.out.println("cause " + me.getCause());
			System.out.println("excep " + me);
			me.printStackTrace();
		}
	}
 
开发者ID:HPCC-Cloud-Computing,项目名称:IoT,代码行数:27,代码来源:MyMqttCloudClient.java

示例6: run

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
public void run() {
	try {
		// Connect to the MQTT Server
		MqttConnectOptions options = new MqttConnectOptions();
		options.setAutomaticReconnect(true);
		options.setCleanSession(true);
		options.setConnectionTimeout(30);
		options.setKeepAliveInterval(30);
		options.setUserName(username);
		options.setPassword(password.toCharArray());
		client = new MqttClient(serverUrl, clientId);
		client.setTimeToWait(5000);						// short timeout on failure to connect
		client.connect(options);
		client.setCallback(this);
		
		// Just listen to all DDATA messages on spAv1.0 topics and wait for inbound messages
		client.subscribe("spBv1.0/#", 0);
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:Cirrus-Link,项目名称:Sparkplug,代码行数:22,代码来源:SparkplugListener.java

示例7: init

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
@PostConstruct
public void init() throws Exception {
    scheduler = Executors.newSingleThreadScheduledExecutor();

    tbClientOptions = new MqttConnectOptions();
    tbClientOptions.setCleanSession(false);
    tbClientOptions.setMaxInflight(connection.getMaxInFlight());
    tbClientOptions.setAutomaticReconnect(true);

    MqttGatewaySecurityConfiguration security = connection.getSecurity();
    security.setupSecurityOptions(tbClientOptions);

    tbClient = new MqttAsyncClient((security.isSsl() ? "ssl" : "tcp") + "://" + connection.getHost() + ":" + connection.getPort(),
            security.getClientId(), persistence.getPersistence());
    tbClient.setCallback(this);

    if (persistence.getBufferSize() > 0) {
        DisconnectedBufferOptions options = new DisconnectedBufferOptions();
        options.setBufferSize(persistence.getBufferSize());
        options.setBufferEnabled(true);
        options.setPersistBuffer(true);
        tbClient.setBufferOpts(options);
    }
    connect();

    scheduler.scheduleAtFixedRate(this::reportStats, 0, reporting.getInterval(), TimeUnit.MILLISECONDS);
}
 
开发者ID:osswangxining,项目名称:iot-edge-greengrass,代码行数:28,代码来源:MqttGatewayService.java

示例8: init

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
@PostConstruct
public void init() throws Exception {
  scheduler = Executors.newSingleThreadScheduledExecutor();

  tbClientOptions = new MqttConnectOptions();
  tbClientOptions.setCleanSession(false);
  tbClientOptions.setMaxInflight(connection.getMaxInFlight());
  tbClientOptions.setAutomaticReconnect(true);

  MqttGatewaySecurityConfiguration security = connection.getSecurity();
  security.setupSecurityOptions(tbClientOptions);

  tbClient = new MqttAsyncClient(
      (security.isSsl() ? "ssl" : "tcp") + "://" + connection.getHost() + ":" + connection.getPort(),
      security.getClientId(), persistence.getPersistence());
  tbClient.setCallback(this);

  if (persistence.getBufferSize() > 0) {
    DisconnectedBufferOptions options = new DisconnectedBufferOptions();
    options.setBufferSize(persistence.getBufferSize());
    options.setBufferEnabled(true);
    options.setPersistBuffer(true);
    tbClient.setBufferOpts(options);
  }
  connect();

  scheduler.scheduleAtFixedRate(this::reportStats, 0, reporting.getInterval(), TimeUnit.MILLISECONDS);
}
 
开发者ID:osswangxining,项目名称:iotgateway,代码行数:29,代码来源:MqttGatewayService.java

示例9: initializeMqttClient

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
private void initializeMqttClient()
    throws MqttException, IOException, NoSuchAlgorithmException, InvalidKeySpecException {

    mqttClient = new MqttClient(mMqttOptions.getBrokerUrl(),
            mMqttOptions.getClientId(), new MemoryPersistence());

    MqttConnectOptions options = new MqttConnectOptions();
    // Note that the the Google Cloud IoT only supports MQTT 3.1.1, and Paho requires that we
    // explicitly set this. If you don't set MQTT version, the server will immediately close its
    // connection to your device.
    options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
    options.setUserName(CloudIotCoreOptions.UNUSED_ACCOUNT_NAME);
    options.setAutomaticReconnect(true);

    // generate the jwt password
    options.setPassword(mqttAuth.createJwt(mMqttOptions.getProjectId()));

    mqttClient.setCallback(this);
    mqttClient.connect(options);

    if(mqttClient.isConnected()) {
        try{
            mSubTopic = "/devices/sense_hub_2.0_android_things/config";// + NetworkUtils.getMACAddress(mContext);
            Log.i(TAG, "initializeMqttClient subscribe topic=" + mSubTopic);
            mqttClient.subscribe(mSubTopic, 1);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    mReady.set(true);
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:32,代码来源:MqttIoTPublisher.java

示例10: initializeMqttClient

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
private void initializeMqttClient()
        throws MqttException, IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    Log.d(TAG, "initializeMqttClient broker=" + mMqttOptions.getBrokerUrl() +
            " clientID=" + mMqttOptions.getClientId() +
            " username=" + mMqttOptions.getUsername() +
            " password=" + mMqttOptions.getPassword());
    mqttClient = new MqttClient(mMqttOptions.getBrokerUrl(),
            mMqttOptions.getClientId(), new MemoryPersistence());

    MqttConnectOptions options = new MqttConnectOptions();
    // Note that the the Google Cloud IoT only supports MQTT 3.1.1, and Paho requires that we
    // explicitly set this. If you don't set MQTT version, the server will immediately close its
    // connection to your device.
    options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
    options.setUserName(mMqttOptions.getUsername());
    options.setPassword(mMqttOptions.getPassword().toCharArray());

    options.setAutomaticReconnect(true);

    mqttClient.setCallback(this);
    mqttClient.connect(options);

    if(mqttClient.isConnected()) {
        try{
            Log.i(TAG, "initializeMqttClient subscribe topic=" + mMqttOptions.getSubscribeTopicName());
            mqttClient.subscribe(mMqttOptions.getSubscribeTopicName(), 1);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    else{
        Log.e(TAG, "Can't connect to " + mMqttOptions.getBrokerUrl());
    }
    mReady.set(true);
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:36,代码来源:MqttPublisher.java

示例11: MqttTestApp

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
public MqttTestApp() throws UnknownHostException, MqttException {
	mqttClient = new MqttClient(mqttUrl, CLIENT_ID_PREFIX + InetAddress.getLocalHost().getHostName(),
			new MemoryPersistence());
	mqttClient.setCallback(this);
	MqttConnectOptions con_opts = new MqttConnectOptions();
	con_opts.setAutomaticReconnect(true);
	con_opts.setCleanSession(true);
	Logger.debug("Connecting to {}...", mqttUrl);
	mqttClient.connect(con_opts);
	Logger.debug("Connected to {}", mqttUrl);

	mqttClient.subscribe("outTopic");
	mqttClient.subscribe(MqttProviderConstants.RESPONSE_TOPIC);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:15,代码来源:MqttTestApp.java

示例12: MqttJsonServer

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
public MqttJsonServer(String mqttUrl) throws UnknownHostException, MqttException {
	mqttClient = new MqttClient(mqttUrl, CLIENT_ID_PREFIX + InetAddress.getLocalHost().getHostName(),
			new MemoryPersistence());
	mqttClient.setCallback(this);
	MqttConnectOptions con_opts = new MqttConnectOptions();
	con_opts.setAutomaticReconnect(true);
	con_opts.setCleanSession(true);
	Logger.debug("Connecting to {}...", mqttUrl);
	mqttClient.connect(con_opts);
	Logger.debug("Connected to {}", mqttUrl);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:12,代码来源:MqttJsonServer.java

示例13: MqttProtobufServer

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
public MqttProtobufServer(String mqttUrl) throws UnknownHostException, MqttException {
	mqttClient = new MqttClient(mqttUrl, CLIENT_ID_PREFIX + InetAddress.getLocalHost().getHostName(),
			new MemoryPersistence());
	mqttClient.setCallback(this);
	MqttConnectOptions con_opts = new MqttConnectOptions();
	con_opts.setAutomaticReconnect(true);
	con_opts.setCleanSession(true);
	Logger.debug("Connecting to {}...", mqttUrl);
	mqttClient.connect(con_opts);
	Logger.debug("Connected to {}", mqttUrl);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:12,代码来源:MqttProtobufServer.java

示例14: run

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
public void run() {
	try {
		// Connect to the MQTT Server
		MqttConnectOptions options = new MqttConnectOptions();
		options.setAutomaticReconnect(true);
		options.setCleanSession(true);
		options.setConnectionTimeout(30);
		options.setKeepAliveInterval(30);
		options.setUserName(username);
		options.setPassword(password.toCharArray());
		client = new MqttClient(serverUrl, clientId);
		client.setTimeToWait(2000);	
		client.setCallback(this);
		client.connect(options);
		
		// Subscribe to control/command messages for both the edge of network node and the attached devices
		client.subscribe(NAMESPACE + "/" + groupId + "/+/" + edgeNode, 0);
		client.subscribe(NAMESPACE + "/" + groupId + "/+/" + edgeNode + "/*", 0);
		
		// Loop to receive input commands
		while (true) {
			System.out.print("\n> ");
			
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String line = br.readLine();

			handleCommand(line);
		}
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:Cirrus-Link,项目名称:Sparkplug,代码行数:33,代码来源:SparkplugExample.java

示例15: createConnectOptions

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //导入方法依赖的package包/类
protected MqttConnectOptions createConnectOptions() {
	MqttConnectOptions connOpts = new MqttConnectOptions();
	connOpts.setUserName(accessKey);
	connOpts.setPassword(sign.toCharArray());
	connOpts.setCleanSession(cleanSession);
	connOpts.setKeepAliveInterval(90);
	connOpts.setAutomaticReconnect(true);
	return connOpts;
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:10,代码来源:LmqClient.java


注:本文中的org.eclipse.paho.client.mqttv3.MqttConnectOptions.setAutomaticReconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。