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


Java MqttMessage.setQos方法代碼示例

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


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

示例1: sendMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public synchronized boolean sendMessage(byte[] messagePayload) {
	logger.info("sending message");
	if (client != null) {
		try {
			MqttMessage message = new MqttMessage(messagePayload);
			message.setQos(qos);
			message.setRetained(false);
			client.publish(topic, message);
			return true;
		} catch (Exception e) {
			logger.error("Failed to send outbound message to topic:  " + topic + " - unexpected issue: " + new String(messagePayload));
			e.printStackTrace();
		}
	} else {
		logger.info("client is null");
	}
	return false;
}
 
開發者ID:edgexfoundry,項目名稱:export-distro,代碼行數:19,代碼來源:IotCoreMQTTSender.java

示例2: sendMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public boolean sendMessage(byte[] messagePayload) {
	if (client != null) {
		try {
			MqttMessage message = new MqttMessage(messagePayload);
			message.setQos(qos);
			message.setRetained(false);
			client.publish(topic, message);
			return true;
		} catch (Exception e) {
			logger.error("Failed to send outbound message to topic:  " + topic + " - unexpected issue: "
					+ new String(messagePayload));
			e.printStackTrace();
		}
	}
	return false;
}
 
開發者ID:edgexfoundry,項目名稱:export-distro,代碼行數:17,代碼來源:MQTTSender.java

示例3: onPublish

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
private void onPublish(final String requestId, final String topic, final byte[] payload) {
    if (!clientIsConnected()) {
        broadcastException(BROADCAST_EXCEPTION, requestId,
                           new Exception("Can't publish to topic: " + topic + ", client not connected!"));
        return;
    }

    try {
        MQTTServiceLogger.debug("onPublish", "Publishing to topic: " + topic + ", payload with size " + payload.length);
        MqttMessage message = new MqttMessage(payload);
        message.setQos(0);
        mClient.publish(topic, message);
        MQTTServiceLogger.debug("onPublish", "Successfully published to topic: " + topic + ", payload: " + payload);

        broadcast(BROADCAST_PUBLISH_SUCCESS, requestId,
                PARAM_TOPIC, topic
        );

    } catch (Exception exc) {
        broadcastException(BROADCAST_EXCEPTION, requestId, new MqttException(exc));
    }
}
 
開發者ID:iGenius-Srl,項目名稱:android-mqtt-service,代碼行數:23,代碼來源:MQTTService.java

示例4: sendMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public boolean sendMessage(byte[] messagePayload) {
  // connectClient();
  if (client != null) {
    try {
      MqttMessage message = new MqttMessage(messagePayload);
      message.setQos(OUTGOING_MQTT_QOS);
      message.setRetained(false);
      client.publish(topic, message);
      return true;
    } catch (Exception e) {
      logger.error(
          "Failed to send outbound message (unexpected issue): " + new String(messagePayload));
      logger.error(e.getLocalizedMessage());
      e.printStackTrace();
    }
  }
  return false;

}
 
開發者ID:edgexfoundry,項目名稱:device-mqtt,代碼行數:20,代碼來源:OutgoingSender.java

示例5: main

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public static void main(String args[]) {
    String topic = "iot/iot";
    String content = "Hello ith";
    int qos = 2;
    String broker = "tcp://127.0.0.1:1883";
    String clientId = "sample";
    MemoryPersistence persistence = new MemoryPersistence();

    try {
        MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
        MqttConnectOptions connOpts = new MqttConnectOptions();
        connOpts.setCleanSession(true);
        System.out.println("Connecting to broker");
        sampleClient.connect(connOpts);
        System.out.println("connected");
        System.out.println("Publishing meessage: " + content);
        MqttMessage message = new MqttMessage(content.getBytes());
        message.setQos(qos);
        sampleClient.publish(topic, message);
        System.out.println("Message published");
        sampleClient.disconnect();
        System.out.println("Disconnected");
        System.exit(0);
    } catch (MqttException e){
        System.out.println("reason " + e.getReasonCode());
        System.out.println("msg " + e.getMessage());
        System.out.println("loc " + e.getLocalizedMessage());
        System.out.println("cause " + e.getCause());
        System.out.println("exxcep " + e);
    }

}
 
開發者ID:dream-lab,項目名稱:echo,代碼行數:33,代碼來源:MQTTPublisher.java

示例6: startAllProcessors

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
private void startAllProcessors() throws MqttException {
    int datagramCount = 0;
    for (Map.Entry<Device, List<Processor>> entry : iProcessorMap.entrySet()) {
        String mqttTopic = entry.getKey().getDeviceUUID();
        ControlDatagram datagram = new ControlDatagram();
        datagram.setAckTopic(sessionId);
        datagram.setSessionId(sessionId);
        datagram.setResourceId(entry.getKey().getDeviceUUID());
        int sequence = 1;
        for (Processor processor : entry.getValue()) {
            ControlMethod method = new ControlMethod();
            method.setMethodName("start_processor");
            method.setSequenceId(sequence++);
            Map<String, String> params = new HashMap<>();
            params.put("proc_id", processor.getNifiId());
            method.setParams(params);
            datagram.addMethod(method);
        }
        String payloadJson = "";
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            payloadJson = objectMapper.writeValueAsString(datagram);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        System.out.println(payloadJson);
        // publish to Mqtt
        MqttMessage message = new MqttMessage(payloadJson.getBytes());
        message.setQos(2);
        mqttClient.publish(mqttTopic, message);
        datagramCount++;
    }
    Map<Integer, ResponseDatagram> responses =
            ControlResponseReceiver.receiveResponse(datagramCount, sessionId, mqttClient.getServerURI());
}
 
開發者ID:dream-lab,項目名稱:echo,代碼行數:36,代碼來源:NifiDeployer.java

示例7: getMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public MqttMessage getMessage() {
    MqttMessage message = new MqttMessage();
    message.setPayload(payload.getBytes());
    message.setQos(QoS);
    message.setRetained(isRetained());
    return message;
}
 
開發者ID:emqtt,項目名稱:EMQ-Android-Toolkit,代碼行數:8,代碼來源:Publication.java

示例8: publishMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
/*********************************************************************************************************************************************************************
 * @param topicPath
 * @param message
 */
public void publishMessage(String messagePath, String message) {

  MqttMessage mqttMessage = new MqttMessage(message.getBytes());
  mqttMessage.setQos(serialMqttBridge.getConfigHandler().getMqttQosPublish());

  String configuredTopicPublish = serialMqttBridge.getConfigHandler().getMqttTopicPublish();
  String mqttPublishTopic = configuredTopicPublish + "/" + messagePath;

  /*
   * If defined: Log outgoing MQTT message
   */
  if (serialMqttBridge.getConfigHandler().logMqttOutbound()) {
    logger.info("MQTT/Out: " + mqttPublishTopic + " | " + message);
  }

  /*
   * Publish MQTT message to broker
   */

  try {
    mqttClient.publish(mqttPublishTopic, mqttMessage);
  }
  catch (Exception e) {
    logger.error("Exception", e);
  }
}
 
開發者ID:DerTomm,項目名稱:SerialMqttBridge,代碼行數:31,代碼來源:MqttHandler.java

示例9: mqttSendMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
protected void mqttSendMessage(String topic, String payload){
    byte[] encodedPayload = new byte[0];
    try {
        encodedPayload = payload.getBytes("UTF-8");
        MqttMessage message = new MqttMessage(encodedPayload);
        message.setRetained(true);
        message.setQos(1);
        client.publish(topic, message);
    } catch (UnsupportedEncodingException | MqttException e) {
        e.printStackTrace();
    }
}
 
開發者ID:chooka888,項目名稱:ConAir,代碼行數:13,代碼來源:ACController.java

示例10: createRemoteConnections

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
private void createRemoteConnections() throws MqttException {

        int datagramCount = 0;
        for (ActualWiring wiring : iGlobalWiring) {
            if (wiring.getSourceType() == ActualWiring.KAFKA_PORT)
                continue;
            String sourceType = wiring.getSourceType();
            ControlDatagram datagram = new ControlDatagram();
            datagram.setSessionId(sessionId);
            datagram.setAckTopic(sessionId);
            ControlMethod method = new ControlMethod();
            method.setSequenceId(1);
            int rpgId;
            int portId;
            if (sourceType.equals(ActualWiring.RPG)) {
                // input port case
                rpgId = wiring.getSourceId();
                portId = wiring.getDestinationId();
                method.setMethodName("connect_remote_input_port");
            } else {
                // output port case
                portId = wiring.getSourceId();
                rpgId = wiring.getDestinationId();
                method.setMethodName("connect_remote_output_port");
            }
            Map<String, String> params = new HashMap<>();
            // get device for rpg
            // get NifiId for rpg
            Pair<Device, NifiRPG> pair = getDeviceAndRpg(rpgId, iRPGMap);
            Device device = pair.getLeft();
            NifiRPG rpg = pair.getRight();
            params.put("rpg", rpg.getNifiId());
            params.put("port_id", getPortId(portId, iPortMap));
            params.put("proc_id", getProcId(rpg.getProcessorId(), iProcessorMap));
            params.put("relationship", rpg.getRelationship());
            // get portId for rpg
            method.setParams(params);
            datagram.setResourceId(device.getDeviceUUID());
            datagram.addMethod(method);

            datagramCount++;
            String payloadJson = "";
            try {
                ObjectMapper objectMapper = new ObjectMapper();
                payloadJson = objectMapper.writeValueAsString(datagram);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }

            MqttMessage message = new MqttMessage(payloadJson.getBytes());
            message.setQos(2);
            String mqttTopic = device.getDeviceUUID();
            mqttClient.publish(mqttTopic, message);
        }
        Map<Integer, ResponseDatagram> responses =
                ControlResponseReceiver.receiveResponse(datagramCount, sessionId, mqttClient.getServerURI());
    }
 
開發者ID:dream-lab,項目名稱:echo,代碼行數:58,代碼來源:NifiDeployer.java


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