Integrate webex webhooks
This commit is contained in:
@@ -3,6 +3,7 @@ package be.naaturel.boardmateapi.services;
|
||||
import be.naaturel.boardmateapi.common.exceptions.ServiceException;
|
||||
import be.naaturel.boardmateapi.common.helpers.Logger;
|
||||
import be.naaturel.boardmateapi.common.models.MqttMessageWrapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -32,14 +33,23 @@ public class MqttService {
|
||||
this.onMessageReceived = consumer;
|
||||
}
|
||||
|
||||
public void publish(String topic, String payload) {
|
||||
public void publish(String topic, Object data) throws ServiceException {
|
||||
try {
|
||||
String payload = new ObjectMapper().writeValueAsString(data);
|
||||
publish(topic, payload);
|
||||
} catch (Exception e){
|
||||
throw new ServiceException("Unable to serialize data", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void publish(String topic, String payload) throws ServiceException {
|
||||
try {
|
||||
connect();
|
||||
MqttMessage message = new MqttMessage(payload.getBytes(StandardCharsets.UTF_8));
|
||||
message.setQos(1);
|
||||
brokerClient.publish(topic, message);
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new ServiceException("Failed to publish on broker", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user