Reactie toevoegen
A while ago, I have posted a blog about tracing messages using end-to-end-logging in Mule 3. However, since we are now building integrations in Mule 4, a new method was required for this purpose. Because the Mule Trace Connector we developed was strongly built on principles that are changed from Mule 3 to Mule 4 (like inbound- and outbound properties and the use of correlation ID’s), it was time for a whole new plugin.
Developing Mule 3 connectors vs. Mule 4 plugins
The major difference between developing custom plugins in Mule 3 and Mule 4, is that Mule 3 connectors were build using the Anypoint Connector DevKit. These connectors should be developed using Anypoint Studio, just like regular Mule projects.
In Mule 4, this has been replaced by the Mule SDK’s. When using the Java SDK, these projects are pure Maven and Java based, so they can be developed in any IDE you want. Also, this makes it much easier to unit test these plugins. This can now be done using JUnit. Mule also provided the MuleArtifactFunctionalTestCase class, which can be used to run a mock Mule flow during a JUnit test.
Mule Trace Plugin for Mule 4
The source and documentation of how to use and implement the Mule Trace Plugin in Mule 4 can be found in Bitbucket.
Using this plugin, you can log messages in a JSON format. The flow name and message- and correlation ID’s (that are generated by Mule, and are also accessible from the Mule flows) will be added to the log message as well. You can also specify a phase, severity and optionally a Map of meta data when logging a message.
{
"traceId": "30fb3e20-a40e-11e9-9bba-34f39ac37765",
"phase": "START",
"metaData": {"hello": "world"},
"messageId": "30fb3e20-a40e-11e9-9bba-34f39ac37765_1601587777",
"message": "Hello world!",
"flow": "mule-trace-connector-exampleFlow"
}
When you have meta data that should be logged for all log messages in a (chain of) flow(s), it’s also possible to persist meta data, even across multiple Mule flows and even applications.
For more (technical) details, the plugin source, guidelines about the implementation and example implementation projects please have a look at the README.md file in the Bitbucket repository:
2 Reacties