5 changed files with 61 additions and 15 deletions
@ -0,0 +1,13 @@ |
|||
package com.galaxis.rcs.communication.amrCommunication; |
|||
|
|||
import org.eclipse.paho.mqttv5.client.IMqttMessageListener; |
|||
import org.eclipse.paho.mqttv5.common.MqttMessage; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Service |
|||
public class AmrMessageHandler implements IMqttMessageListener { |
|||
@Override |
|||
public void messageArrived(String topic, MqttMessage message) throws Exception { |
|||
System.out.println("Received message: " + message.toString()); |
|||
} |
|||
} |
|||
@ -1,27 +1,22 @@ |
|||
package com.galaxis.rcs.communication.amrCommunication; |
|||
|
|||
import org.eclipse.paho.mqttv5.client.IMqttMessageListener; |
|||
import org.eclipse.paho.mqttv5.client.MqttClient; |
|||
import org.eclipse.paho.mqttv5.client.*; |
|||
import org.eclipse.paho.mqttv5.common.MqttException; |
|||
import org.eclipse.paho.mqttv5.common.MqttMessage; |
|||
import org.eclipse.paho.mqttv5.common.packet.MqttProperties; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Service |
|||
public class MqttService implements IMqttMessageListener { |
|||
public class MqttService { |
|||
@Autowired |
|||
private MqttClient mqttClient; |
|||
|
|||
public void subscribe(String topic) throws MqttException { |
|||
mqttClient.subscribe(topic, 0, this); |
|||
mqttClient.subscribe(topic, 0); |
|||
} |
|||
|
|||
public void publish(String topic, String payload) throws MqttException { |
|||
mqttClient.publish(topic, new MqttMessage(payload.getBytes())); |
|||
} |
|||
|
|||
@Override |
|||
public void messageArrived(String topic, MqttMessage message) throws Exception { |
|||
System.out.println("Received message: " + message.toString() + " from topic: " + topic); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue