Search in sources :

Example 1 with MqttClientSslConfig

use of com.hivemq.client.mqtt.MqttClientSslConfig in project open-smart-grid-platform by OSGP.

the class Simulator method main.

public static void main(final String[] args) throws IOException {
    final String spec = getFirstArgOrNull(args);
    final Properties sslServerProperties = new Properties();
    final MqttClientSslConfig sslClientProperties = null;
    final boolean startClient = getSecondArgOrTrue(args);
    final Simulator app = new Simulator();
    app.run(spec, startClient, sslServerProperties, sslClientProperties);
}
Also used : MqttClientSslConfig(com.hivemq.client.mqtt.MqttClientSslConfig) Properties(java.util.Properties)

Example 2 with MqttClientSslConfig

use of com.hivemq.client.mqtt.MqttClientSslConfig 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)

Example 3 with MqttClientSslConfig

use of com.hivemq.client.mqtt.MqttClientSslConfig in project open-smart-grid-platform by OSGP.

the class MqttClient method createClient.

private Mqtt3AsyncClient createClient(final MqttClientDefaults mqttClientDefaults, final MqttClientSslConfig mqttClientSslConfig, final String clientIdentifier) {
    Mqtt3ClientBuilder clientBuilder = Mqtt3Client.builder().identifier(clientIdentifier).serverHost(mqttClientDefaults.getDefaultHost()).serverPort(mqttClientDefaults.getDefaultPort()).sslConfig(mqttClientSslConfig).automaticReconnectWithDefaultConfig().addConnectedListener(context -> LOGGER.info("{} client {} connected to broker at {}:{}", context.getClientConfig().getMqttVersion(), context.getClientConfig().getClientIdentifier().map(MqttClientIdentifier::toString).orElse(clientIdentifier), context.getClientConfig().getServerHost(), context.getClientConfig().getServerPort())).addDisconnectedListener(context -> LOGGER.info("{} client {} disconnected from broker at {}:{}", context.getClientConfig().getMqttVersion(), context.getClientConfig().getClientIdentifier().map(MqttClientIdentifier::toString).orElse(clientIdentifier), context.getClientConfig().getServerHost(), context.getClientConfig().getServerPort()));
    if (StringUtils.isNotEmpty(mqttClientDefaults.getDefaultUsername())) {
        LOGGER.debug("Using username/password for MQTT connection");
        clientBuilder = clientBuilder.simpleAuth().username(mqttClientDefaults.getDefaultUsername()).password(mqttClientDefaults.getDefaultPassword().getBytes()).applySimpleAuth();
    }
    return clientBuilder.buildAsync();
}
Also used : MqttClientState(com.hivemq.client.mqtt.MqttClientState) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) MqttClientSslConfig(com.hivemq.client.mqtt.MqttClientSslConfig) Mqtt3Client(com.hivemq.client.mqtt.mqtt3.Mqtt3Client) Mqtt3ConnAck(com.hivemq.client.mqtt.mqtt3.message.connect.connack.Mqtt3ConnAck) LoggerFactory(org.slf4j.LoggerFactory) MqttQos(com.hivemq.client.mqtt.datatypes.MqttQos) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) UnknownHostException(java.net.UnknownHostException) StringUtils(org.apache.commons.lang3.StringUtils) Mqtt3SubAck(com.hivemq.client.mqtt.mqtt3.message.subscribe.suback.Mqtt3SubAck) InetAddress(java.net.InetAddress) MqttClientIdentifier(com.hivemq.client.mqtt.datatypes.MqttClientIdentifier) Mqtt3AsyncClient(com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient) MqttClientDefaults(org.opensmartgridplatform.adapter.protocol.mqtt.domain.valueobjects.MqttClientDefaults) Mqtt3ClientBuilder(com.hivemq.client.mqtt.mqtt3.Mqtt3ClientBuilder) Mqtt3Publish(com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish) Mqtt3ConnAckReturnCode(com.hivemq.client.mqtt.mqtt3.message.connect.connack.Mqtt3ConnAckReturnCode) Mqtt3SubAckReturnCode(com.hivemq.client.mqtt.mqtt3.message.subscribe.suback.Mqtt3SubAckReturnCode) MqttClientIdentifier(com.hivemq.client.mqtt.datatypes.MqttClientIdentifier) Mqtt3ClientBuilder(com.hivemq.client.mqtt.mqtt3.Mqtt3ClientBuilder)

Aggregations

MqttClientSslConfig (com.hivemq.client.mqtt.MqttClientSslConfig)3 MqttClientState (com.hivemq.client.mqtt.MqttClientState)1 MqttClientIdentifier (com.hivemq.client.mqtt.datatypes.MqttClientIdentifier)1 MqttQos (com.hivemq.client.mqtt.datatypes.MqttQos)1 Mqtt3AsyncClient (com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient)1 Mqtt3Client (com.hivemq.client.mqtt.mqtt3.Mqtt3Client)1 Mqtt3ClientBuilder (com.hivemq.client.mqtt.mqtt3.Mqtt3ClientBuilder)1 Mqtt3ConnAck (com.hivemq.client.mqtt.mqtt3.message.connect.connack.Mqtt3ConnAck)1 Mqtt3ConnAckReturnCode (com.hivemq.client.mqtt.mqtt3.message.connect.connack.Mqtt3ConnAckReturnCode)1 Mqtt3Publish (com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish)1 Mqtt3SubAck (com.hivemq.client.mqtt.mqtt3.message.subscribe.suback.Mqtt3SubAck)1 Mqtt3SubAckReturnCode (com.hivemq.client.mqtt.mqtt3.message.subscribe.suback.Mqtt3SubAckReturnCode)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Arrays (java.util.Arrays)1 Properties (java.util.Properties)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 StringUtils (org.apache.commons.lang3.StringUtils)1 MqttClientDefaults (org.opensmartgridplatform.adapter.protocol.mqtt.domain.valueobjects.MqttClientDefaults)1