use of org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message in project open-smart-grid-platform by OSGP.
the class SimulatorSpecPublishingClient method onConnect.
@Override
void onConnect(final Mqtt3BlockingClient client) {
if (this.hasMessages()) {
while (this.isRunning()) {
final Message message = this.getNextMessage();
this.publish(client, message);
this.pause(message.getPauseMillis());
}
}
}
use of org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message in project open-smart-grid-platform by OSGP.
the class MqttDeviceSteps method startPublishingClient.
private void startPublishingClient(final String host, final int port, final String topic, final String payload, final Map<String, String> parameters) {
final SimulatorSpec spec = new SimulatorSpec(host, port);
spec.setStartupPauseMillis(2000);
final Message message = new Message(topic, payload, 10000);
final Message[] messages = { message };
spec.setMessages(messages);
MqttClientSslConfig mqttClientSslConfig = null;
final boolean mqttSslEnabled = ReadSettingsHelper.getBoolean(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_ENABLED, PlatformDistributionAutomationDefaults.MQTT_SSL_ENABLED);
if (mqttSslEnabled) {
final String truststoreLocation = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_LOCATION, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_LOCATION);
final String truststorePassword = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_PASSWORD, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_PASSWORD);
final String truststoreType = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_TYPE, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_TYPE);
final ResourceLoader resourceLoader = new DefaultResourceLoader();
final Resource trustStoreResource = resourceLoader.getResource(truststoreLocation);
mqttClientSslConfig = MqttClientSslConfigFactory.getMqttClientSslConfig(trustStoreResource, truststorePassword, truststoreType);
}
final SimulatorSpecPublishingClient publishingClient = new SimulatorSpecPublishingClient(spec, mqttClientSslConfig);
publishingClient.start();
}
Aggregations