Create a Message
Digital twins react and respond to messages.
Define a message that data sources will send to instances of this real-time digital twin model (one instance for each data source). The message can be a simple Java bean.
This message represents a temperature change that a Thermostat digital twin instance will react to.
public class TemperatureChangeMessage {
private final int _temperatureChange;
public TemperatureChangeMessage() {
_temperatureChange = 1;
}
public TemperatureChangeMessage(int temperatureChange) {
_temperatureChange = temperatureChange;
}
public int getTemperatureChange() {
return _temperatureChange;
}
// serialize the ExampleMessage -- a 4-byte byte array
public static byte[] serialize(TemperatureChangeMessage msg) {
return ByteBuffer.allocate(4).putInt(msg.getTemperatureChange()).array();
}
// deserialize the ExampleMessage -- a 4-byte byte array.
public static TemperatureChangeMessage deserialize(byte[] bytes) {
int someInt = ByteBuffer.wrap(bytes).getInt();
return new TemperatureChangeMessage(someInt);
}
}