private MqttMessage getMessage( Object[] row ) throws KettleStepException { MqttMessage mqttMessage = new MqttMessage(); try { mqttMessage.setQos( Integer.parseInt( meta.qos ) ); } catch ( NumberFormatException e ) { throw new KettleStepException( getString( PKG, "MQTTProducer.Error.QOS", meta.qos ) ); } mqttMessage.setPayload( getField( row, meta.messageField ) .map( fas -> fas.getBytes( Charsets.UTF_8 ) ) .orElse( null ) ); //allow nulls to pass through return mqttMessage; }
public void publish(String channel, String message) { channel = channel.replaceAll("#", ""); DAO.log("Publishing " + message.substring(0, 10) + " to " + channel); MqttMessage msg = new MqttMessage(message.getBytes()); msg.setQos(this.qos); try { this.client.publish(channel, msg); } catch (MqttException e) { DAO.severe("Failed to publish message to channel " + channel + " due to MQTT exception", e); } catch (IllegalArgumentException e) { DAO.severe("Failed to publish message to channel " + channel + " because of invalid channel name", e); } catch (Exception e) { DAO.severe("Failed to publish message to channel " + channel + " due to unknown exception", e); } }
log.info("Publishing message: " + messageContent); MqttMessage message = new MqttMessage(messageContent.getBytes()); message.setQos(qos); sampleClient.publish(topic, message); log.info("Message published");
public void publishMessage(String topic, String content, Integer qos, Boolean retain) { MqttMessage message = new MqttMessage(StringEscapeUtils.unescapeJava(content).getBytes()); message.setQos(Optional.ofNullable(qos).orElse(1)); message.setRetained(Optional.ofNullable(retain).orElse(false)); try { if(!myClient.isConnected()) { try { myClient.connect(); } catch (MqttSecurityException e1) { log.error("Could not retry connect to MQTT client for name: " + myConfig.getName() + " and ip: " + myConfig.getIp() + " with message: " + e1.getMessage()); return; } catch (MqttException e1) { log.error("Could not retry connect to MQTT client for name: " + myConfig.getName() + " and ip: " + myConfig.getIp() + " with message: " + e1.getMessage()); return; } } myClient.publish(topic, message); } catch (MqttException e) { log.error("Could not publish to MQTT client for name: " + myConfig.getName() + " and ip: " + myConfig.getIp() + " with message: " + e.getMessage()); } }
mqttMessage.setQos(qos); mqttMessage.setPayload(messageContent); mqttMessage.setRetained(context.getProperty(PROP_RETAIN).evaluateAttributeExpressions(flowfile).asBoolean());
/** * Sets up the will information, based on the supplied parameters. * * @param topic the topic to send the LWT message to * @param msg the {@link MqttMessage} to send * @param qos the QoS Level to send the message at * @param retained whether the message should be retained or not */ protected void setWill(String topic, MqttMessage msg, int qos, boolean retained) { willDestination = topic; willMessage = msg; willMessage.setQos(qos); willMessage.setRetained(retained); // Prevent any more changes to the will message willMessage.setMutable(false); }
public IMqttDeliveryToken publish(String topic, byte[] payload, int qos, boolean retained, Object userContext, IMqttActionListener callback) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); return this.publish(topic, message, userContext, callback); }
public void publish(String topic, byte[] payload,int qos, boolean retained) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); this.publish(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. * @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); }
@Override public MqttMessage fromMessage(Message<?> message, Class<?> targetClass) { byte[] payloadBytes = messageToMqttBytes(message); MqttMessage mqttMessage = new MqttMessage(payloadBytes); Integer qos = this.qosProcessor.processMessage(message); mqttMessage.setQos(qos == null ? this.defaultQos : qos); Boolean retained = this.retainedProcessor.processMessage(message); mqttMessage.setRetained(retained == null ? this.defaultRetained : retained); return mqttMessage; }
/** * Constructs a new MqttPublish object. * @param info the message info byte * @param data the variable header and payload bytes * @throws MqttException if an exception occurs creating the publish * @throws IOException if an exception occurs creating the publish */ public MqttPublish(byte info, byte[] data) throws MqttException, IOException { super(MqttWireMessage.MESSAGE_TYPE_PUBLISH); message = new MqttReceivedMessage(); message.setQos((info >> 1) & 0x03); if ((info & 0x01) == 0x01) { message.setRetained(true); } if ((info & 0x08) == 0x08) { ((MqttReceivedMessage) message).setDuplicate(true); } ByteArrayInputStream bais = new ByteArrayInputStream(data); CountingInputStream counter = new CountingInputStream(bais); DataInputStream dis = new DataInputStream(counter); topicName = decodeUTF8(dis); if (message.getQos() > 0) { msgId = dis.readUnsignedShort(); } byte[] payload = new byte[data.length-counter.getCounter()]; dis.readFully(payload); dis.close(); message.setPayload(payload); }
try { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); sendToken = myClient.publish(topic, payload, qos, retained,
message.setQos(qos); message.setRetained(retained); MqttDeliveryTokenAndroid token = new MqttDeliveryTokenAndroid(
private void publish(JsonObject jsonPubMsg) throws MqttException, UnsupportedEncodingException { final String METHOD = "publish1"; String topic = jsonPubMsg.get("topic").getAsString(); int qos = jsonPubMsg.get("qos").getAsInt(); JsonObject payload = jsonPubMsg.getAsJsonObject("payload"); LoggerUtility.log(Level.FINE, CLASS_NAME, METHOD, ": Topic(" + topic + ") qos=" + qos + " payload (" + payload.toString() + ")"); MqttMessage message = new MqttMessage(); message.setPayload(payload.toString().getBytes("UTF-8")); message.setQos(qos); publish(topic, message); }
private void publish(JsonObject jsonPubMsg) throws MqttException, UnsupportedEncodingException { final String METHOD = "publish1"; String topic = jsonPubMsg.get("topic").getAsString(); int qos = jsonPubMsg.get("qos").getAsInt(); JsonObject payload = jsonPubMsg.getAsJsonObject("payload"); LoggerUtility.log(Level.FINE, CLASS_NAME, METHOD, ": Topic(" + topic + ") qos=" + qos + " payload (" + payload.toString() + ")"); MqttMessage message = new MqttMessage(); message.setPayload(payload.toString().getBytes("UTF-8")); message.setQos(qos); publish(topic, message); }
public void publishMessage(@NonNull MqttAndroidClient client, @NonNull String msg, int qos, @NonNull String topic) throws MqttException, UnsupportedEncodingException { byte[] encodedPayload = new byte[0]; encodedPayload = msg.getBytes("UTF-8"); MqttMessage message = new MqttMessage(encodedPayload); message.setId(320); message.setRetained(true); message.setQos(qos); client.publish(topic, message); }
/** * Sets up the will information, based on the supplied parameters. */ protected void setWill(String topic, MqttMessage msg, int qos, boolean retained) { willDestination = topic; willMessage = msg; willMessage.setQos(qos); willMessage.setRetained(retained); // Prevent any more changes to the will message willMessage.setMutable(false); }
public IMqttDeliveryToken publish(String topic, byte[] payload, int qos, boolean retained, Object userContext, IMqttActionListener callback) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); return this.publish(topic, message, userContext, callback); }
public void publish(String topic, byte[] payload,int qos, boolean retained) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); this.publish(topic, message); }
public void publish(String topic, byte[] payload,int qos, boolean retained) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); this.publish(topic, message); }