Developing Solutions Locally

At this point it is assumed, that the initial setup and the mandatory commands of the Solution CLI have been performed and executed as described. Follow the steps below if you want to test a Java solution locally:

There are two configuration approaches to start your solution locally:
  • Have a valid deployed solution and use its k8s configuration maps to load bindings for MongoDB and Kafka.
  • Provide configuration values to connect to your local MongoDB and Kafka broker.
Attention: If you choose to use deployed solution k8s configuration maps , you need to login to your OpenShift cluster via OC CLI and run proper OC proxy command to be able to connect to your OpenShift namespace MongoDB and Kafka clusters.
  1. Create an application-local.yaml file and override properties needed for the local profile.
  2. Depending on which configuration approach from above add either your OpenShift k5-project namespace or a dummy namespace mock value.
    de.knowis.cp.consumer.kubernetes.mockNamespace: "mock-namespace"
  3. Add your solution acronym.
    solution.acronym : "solution acronym"
  4. To load MongoDB configuration from k8s configuration map.
    
    de.knowis.cp.common.mongo.autoconfiguration.enabled: true
    
    #mongoDb configuration from k8s secret
    spring.data.mongodb.secretName: "k5-default-document-storage-service-binding"
    
  5. To access local MongoDB, you can set the spring.data.mongodb.uri property to change the URL and configure additional settings such as the replica set, as shown in the following example:
    
    spring:
      data:
        mongodb:
        uri=mongodb://<username>:<secret>@<host>:<port>/<database>
            
    Alternatively, you can specify connection details using discrete properties. For example, you might declare the following settings as shown below:
    
    spring:
      data:
        mongodb:
        host: <host>
        port: <port>
        database: <database>
        username: <username>
        password: <password>
            
  6. To load Kafka binding configuration from k8s configuration map.
    
    feature.kafka-events.enabled: true
    de.knowis.cp.consumer.kafka.binding.enabled: true
    
    #Kafka configuration from k8s secret
    de.knowis.cp.consumer.kafka.bindingSecretName: "k5-default-message-service-binding"
    
  7. To configure local Kafka broker, you can set the de.knowis.cp.consumer.kafka.binding properties to change the bootstrap URL and configure additional settings such as your Kafka topic pattern and group Id, as shown in the following example:
    
    feature.kafka-events.enabled: true
    de.knowis.cp.consumer.kafka.binding:
      kafka_brokers_sasl: "localhost:2181"
      user: <username>
      password: <password>
      topicPattern: "basePackage.solutionAcornym.*"
      groupId: "basePackage.solutionAcornym"
    
  8. To configure Swagger UI for local development, use the settings below:
    
    springdoc:
      api-docs:
        enabled: true
        path: /<solutionAcronym>/api-docs
      swagger-ui:
        oauth:
        clientId: <client-id>
            
  9. If you have spring-security-oauth2-client on your classpath, you can take advantage of some auto-configuration to set up an OAuth2/Open ID Connect client, as shown in the following example:
    
    spring:
      security:
        oauth2:
          client:
            registration:
              my-client-1:
              client-id: <client-id>
              client-secret: <secret>
              client-name: <client-for-user-scope>
              provider: <provider-name>
              scope: <scope>
              redirect-uri: <redirect-url>
              client-authentication-method: <authentication-type>
              authorization-grant-type: <grant-type>
            provider:
              oidc-provider:
              issuer-uri: <issuer-url>
            
  10. Build and run the code. Pass the configuration below in jvm arguments to use the local profile.
    
              -Dspring.profiles.active=local
            
Note: Refer to Sprint Boot's official documentation for more details on MongoDB and Kafka additional configuration.