/** * Publishes a message on the topic. This is a convenience method, which will * create a new {@link MqttMessage} object with a byte array payload and the * specified QoS, and then publish it. All other values in the * message will be set to the defaults. * @param payload the byte array to use as the payload * @param qos the Quality of Service. Valid values are 0, 1 or 2. * @param retained whether or not this message should be retained by the server. * @return {@link MqttDeliveryToken} * @throws MqttException If an error occurs publishing the message * @throws MqttPersistenceException If an error occurs persisting the message * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. * @see #publish(MqttMessage) * @see MqttMessage#setQos(int) * @see MqttMessage#setRetained(boolean) */ public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); return this.publish(message); }
MqttTopic mqttTopic = client.getTopic(topic); mqttTopic.publish(message.getBytes(), 0, false);
MqttDeliveryToken token; ... MqttTopic mqttTopic = client.getTopic(topic); try { // Publish to the broker token = mqttTopic.publish(new MqttMessage(pubMsg.getBytes())); logOutgoingMessage(topic, message); ... }
/** * Publishes a message on the topic. This is a convenience method, which will * create a new {@link MqttMessage} object with a byte array payload and the * specified QoS, and then publish it. All other values in the * message will be set to the defaults. * @param payload the byte array to use as the payload * @param qos the Quality of Service. Valid values are 0, 1 or 2. * @param retained whether or not this message should be retained by the server. * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. * @see #publish(MqttMessage) * @see MqttMessage#setQos(int) * @see MqttMessage#setRetained(boolean) */ public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); return this.publish(message); }
/** * Publishes a message on the topic. This is a convenience method, which will * create a new {@link MqttMessage} object with a byte array payload and the * specified QoS, and then publish it. All other values in the * message will be set to the defaults. * @param payload the byte array to use as the payload * @param qos the Quality of Service. Valid values are 0, 1 or 2. * @param retained whether or not this message should be retained by the server. * @return {@link MqttDeliveryToken} * @throws MqttException If an error occurs publishing the message * @throws MqttPersistenceException If an error occurs persisting the message * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. * @see #publish(MqttMessage) * @see MqttMessage#setQos(int) * @see MqttMessage#setRetained(boolean) */ public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); return this.publish(message); }
/** * Publishes a message on the topic. This is a convenience method, which will * create a new {@link MqttMessage} object with a byte array payload and the * specified QoS, and then publish it. All other values in the * message will be set to the defaults. * @param payload the byte array to use as the payload * @param qos the Quality of Service. Valid values are 0, 1 or 2. * @param retained whether or not this message should be retained by the server. * @return {@link MqttDeliveryToken} * @throws MqttException If an error occurs publishing the message * @throws MqttPersistenceException If an error occurs persisting the message * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. * @see #publish(MqttMessage) * @see MqttMessage#setQos(int) * @see MqttMessage#setRetained(boolean) */ public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); return this.publish(message); }
MqttTopic mtopic=mqttClient.getTopic(this.topic); MqttMessage msg= new MqttMessage(message.getBytes()); mtopic.publish(msg); } catch (MqttException e) { Log.e(TAG, "Error while publishing to mqtt broker: "+e.toString());
throw new AxisFault("Invalid value for qos " + qos); mqttTopic.publish(mqttMessage);