Skip to content

Latest commit

 

History

History
234 lines (182 loc) · 9.68 KB

File metadata and controls

234 lines (182 loc) · 9.68 KB

Debugging Mule Applications

reuse::partial$beta-banner.adoc

Debug your Mule application using the embedded debugger in Anypoint Code Builder.

The process for debugging a Mule app is:

  1. Set breakpoints to pause the execution of a flow at lines that you want to inspect or fix.

    Breakpoints are markers that you add on line numbers in a configuration XML file for a Mule application that you are developing.

  2. Run the application in debug mode.

  3. Start execution of a flow in your Mule application.

    For example, trigger an HTTP Listener or configure a Scheduler component.

  4. When the execution stops at a breakpoint, use the debug toolbar to navigate, inspect, and fix issues.

  5. After addressing an issue at a breakpoint, redeploy (hot deploy) the running instance of your application.

  6. Execute your flow again, and continue debugging until you address all issues.

  7. Stop the debug session.

Debug Console Overview

Elements of the debugger view
  1. Start Debugging: Starts an instance of a Mule application in debugging mode.

  2. Debug Toolbar: Controls debugging of Mule applications.

  3. Variables panel: Provides Mule event and parameter data.

    The Mule event includes message payload and attribute details, as well as Mule variable data. The parameters include component data, such as the component name.

  4. Run and Debug (MuleSoft) icon: Opens the Run and Debug panel, where you can click Start Debugging (F5) and find debugging information.

    Keyboard shortcut: Cmd+Shift+d (Mac) or Ctrl+Shift+d (Windows)

  5. Watch panel: Helps you evaluate variables and expressions.

  6. Call Stack panel: Identifies the functions or procedures that are currently in the stack.

  7. Breakpoints panel: Lists all breakpoints in your Mule application.

  8. Terminal console: Displays the output of the Maven build process and the results of the deployment to the embedded Mule Runtime engine.

  9. Breakpoint icon: Identifies a line in the configuration XML to pause execution of the flow so that you can check for and fix any issues.

  10. Breakpoint icon: Identifies a component that contains one or more breakpoints.

Add a Breakpoint

A breakpoint enables you to pause your Mule application at a specific place to learn more about what is happening. You can either add a breakpoint to a configuration XML file or to a component in the canvas UI.

Add a Breakpoint in a Configuration File

To add a breakpoint in a configuration XML file:

  1. In Anypoint Code Builder, on the Explorer view, open your configuration XML file, for example, my-project-name.xml. partial$acb-reusable-steps.adoc

  2. Click the line number in your <flow-ref> component to add a breakpoint on that component:

    Add breakpoint on a line number

    You can also use F9 to add a breakpoint to the current line.

  3. In your configuration XML file, add two more breakpoints for the <db:select> and the <set-variable> components.

    All breakpoints appear in the Breakpoints panel:

    Breakpoints panel

Add a Breakpoint to a Component in the Canvas UI

To add a breakpoint to a component in the canvas UI:

  1. In Anypoint Code Builder, on the Explorer view, open your configuration XML file, for example, flights-implementation.xml. partial$acb-reusable-steps.adoc

  2. In the canvas UI, right-click on the component you want to add a breakpoint to:

    Add breakpoint to a component in the canvas UI
  3. Select Add Breakpoint.

    A breakpoint icon appears on the component and in the configuration XML for that component.

Add a Breakpoint to a Batch Component

Add a breakpoint to a batch component in the canvas UI or in a configuration XML file:

  1. In Anypoint Code Builder, on the Explorer view, open your configuration XML file, for example, batch-example.xml. partial$acb-reusable-steps.adoc

  2. In the canvas UI or XML editor, select the batch component where you want to pause execution.

    You can add breakpoints to these components: * Batch Job (<batch:job/>) * Batch Step (<batch:step/>) * Batch Aggregator (<batch:aggregator/>)

  3. Right-click the component in the canvas UI and select Add Breakpoint, or click the line number in the XML editor.

    A breakpoint icon appears on the component and in the configuration XML for that component.

  4. Run the application in debug mode.

    When execution reaches the breakpoint, processing pauses so you can inspect variables, payloads, and the execution state in the Debug panel.

Note
Batch execution is concurrent. Multiple record blocks can be processed in parallel, so breakpoints can trigger on different threads. The Debug panel displays each thread context separately so you can inspect each execution path.

Run Your Application in Debug Mode

After setting up your debug conditions, run a debug session and evaluate your Mule application at each breakpoint:

anypoint-code-builder::partial$acb-reusable-steps.adoc anypoint-code-builder::partial$acb-reusable-steps.adoc

Note
Selecting Run > Start without Debugging produces an error.

Anypoint Code Builder packages your application and deploys the application to the embedded Mule runtime engine. A terminal opens so you can view the status:

Debugging status in a terminal window

The terminal displays a message and the status bar turns red to indicate that the application is running.

Use buttons on the debug toolbar to control debugging of Mule applications.

Debug Toolbar

Debug toolbar
  1. Continue F5

    Proceeds to the next breakpoint, if present, and pauses execution of the application. Otherwise, continues to the end of the application.

  2. Step Over F10

    Proceeds to the next component in the flow, where execution pauses. At a Flow Ref component (<flow-ref/>), clicking Step Over proceeds to the next component in the flow but does not follow the Flow Ref logic to a referenced flow or proceed to another flow.

    Step Over Details

    Configuration XML example:

    <flow name="flow1" doc:name="Flow" >
      <http:listener path="greet" config-ref="HTTP_Listener_config" doc:name="Listener"/>
      <flow-ref name="myNewFlow" /> <!--(1)-->
      <logger doc:name="Logger1" message="test1"/> <!--(2)-->
    </flow>
    
    <flow name="flow2" doc:name="Flow" >
      <logger doc:name="Logger2" message="test2"/>
    </flow>

    Step Over behavior:

    1. Skips <flow-ref/> logic

    2. Reaches <logger/> named Logger1

  3. Step Into F11

    Proceeds to the next component in the flow, where execution pauses. At a Flow Ref component (<flow-ref/>), clicking Step Into follows the logic of the component and proceeds to the first component in the referenced flow. If a component in a flow follows a Flow Ref component, Step Into returns to that component after the last component in the referenced flow (or flows).

    Step Into Details

    Configuration XML example:

    <flow name="flow1" doc:name="Flow" >
      <http:listener path="greet" config-ref="HTTP_Listener_config" doc:name="Listener"/>
      <flow-ref name="myNewFlow" /> <!--(1)-->
      <logger doc:name="Logger1" message="test1"/> <!--(3)-->
    </flow>
    
    <flow name="myNewFlow" doc:name="Flow" >
      <logger doc:name="Logger2" message="test2"/> <!--(2)-->
    </flow>

    Step Into behavior:

    1. Enters <flow-ref/> to follow logic to myNewFlow

    2. Reaches Logger2 in next flow, myNewFlow

    3. Returns to flow flow1 to reach Logger1

  4. Step Out Shift+F11

    Exits the current flow and attempts to return to a previous flow. If a previous flow doesn’t exist, the debugger behaves like Continue.

  5. Restart Shift+Cmd+F5 (Mac) or Shift+Ctrl+F5 (Windows)

    Stop and restart the application without packaging new dependencies, such as new connector dependencies in your pom.xml file.

  6. Stop Shift+F5

    Stop execution of the application. The next debugging session that you start packages the application with any new dependencies.

Perform a Hot Deploy When Debugging

As you debug your application, periodically perform a hot deployment. A hot deployment updates a running instance of your application but does not package new dependencies, such as new connector dependencies in your pom.xml.

To perform a hot deploy:

  1. Ensure your Mule application is running in the IDE.

  2. Make an update to your application.

  3. Click the Save and Hot-deploy to Mule Runtime (lightning) icon to deploy the application with the change:

    Hot-deploy (lightning) icon in a running Mule application

Stop a Debug Session

To stop your debug session, in the Run and Debug panel, click the (Stop) icon.

The status bar no longer indicates that the application is running.