public MQTTQueueMessage(String topic, MqttMessage message) { this.topic = topic; payload = message.getPayload(); qos = message.getQos(); retained = message.isRetained(); duplicate = message.isDuplicate(); }
protected byte getMessageInfo() { byte info = (byte) (message.getQos() << 1); if (message.isRetained()) { info |= 0x01; } if (message.isDuplicate() || duplicate ) { info |= 0x08; } return info; }
sb.append(" msgId:").append(msgId); sb.append(" retained:").append(message.isRetained()); sb.append(" dup:").append(duplicate); sb.append(" topic:\"").append(topicName).append("\"");
connectFlags |= 0x04; connectFlags |= (willMessage.getQos()<<3); if (willMessage.isRetained()) { connectFlags |= 0x20;
/** * @see org.eclipse.paho.client.mqttv3.MqttCallback#messageArrived(java.lang.String, org.eclipse.paho.client.mqttv3.MqttMessage) */ @Override public void messageArrived(String topic, MqttMessage message) throws Exception { //Get connection object associated with this object Connection c = Connections.getInstance(context).getConnection(clientHandle); c.messageArrived(topic, message); //get the string from strings.xml and format String messageString = context.getString(R.string.messageRecieved, new String(message.getPayload()), topic+";qos:"+message.getQos()+";retained:"+message.isRetained()); Log.i(TAG, messageString); //update client history c.addAction(messageString); }
private ContentValues getValues(Connection connection){ MqttConnectOptions conOpts = connection.getConnectionOptions(); MqttMessage lastWill = conOpts.getWillMessage(); ContentValues values = new ContentValues(); //put the column values object values.put(COLUMN_CLIENT_HANDLE, connection.handle()); values.put(COLUMN_HOST, connection.getHostName()); values.put(COLUMN_port, connection.getPort()); values.put(COLUMN_client_ID, connection.getId()); values.put(COLUMN_ssl, connection.isSSL()); values.put(COLUMN_KEEP_ALIVE, conOpts.getKeepAliveInterval()); values.put(COLUMN_TIME_OUT, conOpts.getConnectionTimeout()); values.put(COLUMN_USER_NAME, conOpts.getUserName()); values.put(COLUMN_TOPIC, conOpts.getWillDestination()); //uses "condition ? trueValue: falseValue" for in line converting of values char[] password = conOpts.getPassword(); values.put(COLUMN_CLEAN_SESSION, conOpts.isCleanSession() ? 1 : 0); //convert boolean to int and then put in values values.put(COLUMN_PASSWORD, password != null ? String.valueOf(password) : null); //convert char[] to String values.put(COLUMN_MESSAGE, lastWill != null ? new String(lastWill.getPayload()) : null); // convert byte[] to string values.put(COLUMN_QOS, lastWill != null ? lastWill.getQos() : 0); if (lastWill == null) { values.put(COLUMN_RETAINED, 0); } else { values.put(COLUMN_RETAINED, lastWill.isRetained() ? 1 : 0); //convert from boolean to int } return values; }
boolean retained = message.isRetained(); boolean duplicate = message.isDuplicate();
ParcelableMqttMessage(MqttMessage original) { super(original.getPayload()); setQos(original.getQos()); setRetained(original.isRetained()); setDuplicate(original.isDuplicate()); }
/** * Get a Last Will and Testament message's "retained" setting. * @return the value. */ public boolean getWillRetained() { MqttMessage msg = options.getWillMessage(); return msg==null ? false : msg.isRetained(); }
@Override public Message<?> toMessage(String topic, MqttMessage mqttMessage) { try { AbstractIntegrationMessageBuilder<?> messageBuilder; if (this.bytesMessageMapper != null) { messageBuilder = getMessageBuilderFactory() .fromMessage(this.bytesMessageMapper.toMessage(mqttMessage.getPayload())); } else { messageBuilder = getMessageBuilderFactory() .withPayload(mqttBytesToPayload(mqttMessage)); } messageBuilder .setHeader(MqttHeaders.RECEIVED_QOS, mqttMessage.getQos()) .setHeader(MqttHeaders.DUPLICATE, mqttMessage.isDuplicate()) .setHeader(MqttHeaders.RECEIVED_RETAINED, mqttMessage.isRetained()); if (topic != null) { messageBuilder.setHeader(MqttHeaders.RECEIVED_TOPIC, topic); } return messageBuilder.build(); } catch (Exception e) { throw new MessageConversionException("failed to convert object to Message", e); } }
@SuppressWarnings("unchecked") @Test public void testCustomExpressions() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class); MqttPahoMessageHandler handler = ctx.getBean("handler", MqttPahoMessageHandler.class); GenericMessage<String> message = new GenericMessage<>("foo"); assertEquals("fooTopic", TestUtils.getPropertyValue(handler, "topicProcessor", MessageProcessor.class).processMessage(message)); assertEquals(1, TestUtils.getPropertyValue(handler, "converter.qosProcessor", MessageProcessor.class) .processMessage(message)); assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(handler, "converter.retainedProcessor", MessageProcessor.class) .processMessage(message)); handler = ctx.getBean("handlerWithNullExpressions", MqttPahoMessageHandler.class); assertEquals(1, TestUtils.getPropertyValue(handler, "converter", DefaultPahoMessageConverter.class) .fromMessage(message, null).getQos()); assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(handler, "converter", DefaultPahoMessageConverter.class) .fromMessage(message, null).isRetained()); ctx.close(); }
lwtMessage = new String(connection.getConnectionOptions().getWillMessage().getPayload()); lwtQos = connection.getConnectionOptions().getWillMessage().getQos(); lwtRetain = connection.getConnectionOptions().getWillMessage().isRetained(); } else { lwtMessage = "";
protected byte getMessageInfo() { byte info = (byte) (message.getQos() << 1); if (message.isRetained()) { info |= 0x01; } if (message.isDuplicate() || duplicate ) { info |= 0x08; } return info; }
@Override public void messageArrived(String topic, MqttMessage message) throws Exception { String msgContent = new String(message.getPayload()); String detailLog = topic + ";qos:" + message.getQos() + ";retained:" + message.isRetained(); Log.i(TAG, "messageArrived:" + msgContent); Log.i(TAG, detailLog); if (starMQTTCallBack != null) { starMQTTCallBack.messageArrived(topic, msgContent, message.getQos()); } }
@Test public void testConnectWithLwt() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", AWSIotMqttQos.QOS0); testClient.setMqttLastWillAndTestament(lwt); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper .getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); mockClient.mockConnectSuccess(); assertEquals(1, mockClient.connectCalls); assertTrue(mockClient.mostRecentOptions.isCleanSession()); assertEquals(300, mockClient.mostRecentOptions.getKeepAliveInterval()); assertEquals("test/lwt", mockClient.mostRecentOptions.getWillDestination()); assertEquals("bye", new String(mockClient.mostRecentOptions.getWillMessage().getPayload())); assertEquals(AWSIotMqttQos.QOS0.asInt(), mockClient.mostRecentOptions.getWillMessage().getQos()); assertFalse(mockClient.mostRecentOptions.getWillMessage().isRetained()); assertEquals(2, csb.statuses.size()); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connecting, csb.statuses.get(0)); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connected, csb.statuses.get(1)); assertEquals(MqttManagerConnectionState.Connected, testClient.getConnectionState()); }
/** * Creates a new message from the given mqtt message * * @param msg * the mqtt message */ protected MessageImpl(MqttMessage msg) { this.data = new String(msg.getPayload(), StandardCharsets.UTF_8); this.qos = msg.getQos(); this.duplicate = msg.isDuplicate(); this.retained = msg.isRetained(); }
@Test public void testWithDefaultConverter() { GenericMessage<String> message = new GenericMessage<>("foo"); assertEquals("tcp://localhost:1883", TestUtils.getPropertyValue(withDefaultConverterHandler, "url")); assertEquals("foo", TestUtils.getPropertyValue(withDefaultConverterHandler, "clientId")); assertEquals("bar", TestUtils.getPropertyValue(withDefaultConverterHandler, "defaultTopic")); assertEquals(1, TestUtils.getPropertyValue(withDefaultConverterHandler, "defaultQos")); assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(withDefaultConverterHandler, "defaultRetained", Boolean.class)); DefaultPahoMessageConverter defaultConverter = TestUtils.getPropertyValue(withDefaultConverterHandler, "converter", DefaultPahoMessageConverter.class); assertEquals(1, defaultConverter.fromMessage(message, null).getQos()); assertTrue(defaultConverter.fromMessage(message, null).isRetained()); assertSame(clientFactory, TestUtils.getPropertyValue(withDefaultConverterHandler, "clientFactory")); assertTrue(TestUtils.getPropertyValue(withDefaultConverterHandler, "async", Boolean.class)); assertTrue(TestUtils.getPropertyValue(withDefaultConverterHandler, "asyncEvents", Boolean.class)); }
ParcelableMqttMessage(MqttMessage original) { super(original.getPayload()); setQos(original.getQos()); setRetained(original.isRetained()); setDuplicate(original.isDuplicate()); }
ParcelableMqttMessage(MqttMessage original) { super(original.getPayload()); setQos(original.getQos()); setRetained(original.isRetained()); setDuplicate(original.isDuplicate()); }
assertEquals(AWSIotMqttQos.QOS0.asInt(), mockClient.mostRecentOptions.getWillMessage().getQos()); assertFalse(mockClient.mostRecentOptions.getWillMessage().isRetained());