Create simulation from learning mode

Learning mode allows virtual services to learn the behavior of real services by monitoring their interactions. It helps you capture the actual request-response behavior of the service in real time, which you can then use to build and improve your simulations. This is also useful if you don't have a predefined specification or contract for the service you want to virtualize.

To use learning mode, add the forward and mode connection properties with the learning value to your connection. Every time the simulation fails, the message is forwarded to the real service. The connection learns the new behavior and automatically saves it as a new simulation file. You can find the simulation files in the simulation registry.

When API simulation creates the simulation file, it tries to automatically detect possible trigger elements and save them as trigger properties.

Example for car service

This example sets up a connection called theCarServiceSimLearnings with the following details:

  • The connection type is forward with learning mode.

  • It listens on port 54345 and captures requests sent to /carservice.

  • The patterns property uses an XPath rule to extract the make element from SOAP requests by navigating through the Envelope > Body > getCar structure. For each extracted make, it updates the simulation file and forwards the request to the realCarService.

  • The realCarService endpoint is http://localhost:51002/carservice.

  • The endpoint's listen mode is set to false, meaning the Simulator agent doesn't use the endpoint to receive messages but only forwards traffic to it.

Copy
schema: SimV1
connections:
- forward:
    learning:
      patterns:
      - type: Path
      - xPath: /*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='getCar']/*[local-name()='make']
    mode: Learning
    to: realCarService
  name: theCarServiceSimLearnings
  port: 54345

- endpoint: http://localhost:51002/carservice
  listen: false
  name: realCarService