Search in sources :

Example 1 with Message

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());
        }
    }
}
Also used : Message(org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message)

Example 2 with Message

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();
}
Also used : MqttClientSslConfig(com.hivemq.client.mqtt.MqttClientSslConfig) SimulatorSpecPublishingClient(org.opensmartgridplatform.simulator.protocol.mqtt.SimulatorSpecPublishingClient) ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Message(org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message) Resource(org.springframework.core.io.Resource) SimulatorSpec(org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Aggregations

Message (org.opensmartgridplatform.simulator.protocol.mqtt.spec.Message)2 MqttClientSslConfig (com.hivemq.client.mqtt.MqttClientSslConfig)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 SimulatorSpecPublishingClient (org.opensmartgridplatform.simulator.protocol.mqtt.SimulatorSpecPublishingClient)1 SimulatorSpec (org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec)1 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)1 Resource (org.springframework.core.io.Resource)1 ResourceLoader (org.springframework.core.io.ResourceLoader)1