Migrate from things-client to ditto-client

In cases you have started to implement your solution using the things-client and need to migrate to the ditto-client, first of all you will need to configure your Maven settings in order do get the Ditto Java packages.

See FAQ > How to configure my Maven settings?

The authentication can be done via a Json Web Access Token, issued by an OAuth provider of your choice. The token can be requested and refreshed by using the ClientCredentialsAuthentication of the ditto-client.

Find an example at github.com/bosch-io/iot-things-examples.

The initialization of a ditto-client works the same way as it works for a things-client.

Example:

private DittoClient initializeDittoClient() {
  // Build a client-credential authentication configuration if you want to directly connect to the IoT Things service
  // via its websocket channel
  final ClientCredentialsAuthenticationConfiguration.ClientCredentialsAuthenticationConfigurationBuilder
          clientCredentialsAuthenticationConfigurationBuilder =
          ClientCredentialsAuthenticationConfiguration.newBuilder()
                  .clientId(clientId)
                  .clientSecret(clientSecret)
                  .scopes(getScopesAsList(scopes))
                  .tokenEndpoint(tokenEndpoint);
  
  final MessagingConfiguration.Builder messagingProviderConfigurationBuilder = WebSocketMessagingConfiguration.
          newBuilder()
          .jsonSchemaVersion(JsonSchemaVersion.V_2)
          .reconnectEnabled(false)
          .endpoint(endpoint_ws);
  
  proxyConfiguration().ifPresent(messagingProviderConfigurationBuilder::proxyConfiguration);
  proxyConfiguration().ifPresent(clientCredentialsAuthenticationConfigurationBuilder::proxyConfiguration);
  
  MessagingProvider messagingProvider =
          MessagingProviders.webSocket(messagingProviderConfigurationBuilder.build(),
                  AuthenticationProviders.clientCredentials(
                          clientCredentialsAuthenticationConfigurationBuilder.build()));
  return DittoClients.newInstance(messagingProvider);

tip Find further examples at https://github.com/eclipse/ditto-examples/tree/master/java-client.

Imprint Legal info Privacy statement