Logging mule flow with DerbyDb – Part 2

In my previous post I’ve shown how create Derby instance and use it in Mule configuration file. 

Now it’s time to write mule inbound/outbound message and access to it from http browser.

Log inbound/Outbound message

Have you ever tried to open the source code files or follow the debug inside that?

I’ve tried it and I’ve found very interesting experience. First of all because the code is very well written and it’s very useful if you have to understand some code behaviour that is not clearly documented.

If you look inside org.mule.component.AbstractComponent at the method invokeInternal you can see that all messages inbound pass trough this point (or, at least, all my messages in the flow).

private MuleMessage invokeInternal(MuleEvent event)
        throws DisposeException, DefaultMuleException, MuleException, ServiceException
{
...
      //Log Inbound Message
     DbFactory.WriteLog(event, "INBOUND");
...
}

The same happens in the class org.mule.DefaultMuleSession at the method dispatchEvent. If the endpoint type is Outbound you can check here all messages outbound pass trough this point. 

public void dispatchEvent(MuleEvent event) throws MuleException
{
    if (event.getEndpoint() instanceof OutboundEndpoint)
    {
        try
        {
         //Log Outbound Message
         DbFactory.WriteLog(event, "OUTBOUND");
        }
      ...
    }
  ...
}

Access Log from Http Browser

Once the data are in database, we can access it by http browser. For complete this task we have to:

  • Create http endpoint
  • Serialize data
  • Apply a Xsl Trasformation for build a clear layout.

Create http endpoint it’s a very easy task:

<mulexml:xslt-transformer name="xslt" xsl-file="logview.xslt" />
<custom-transformer name="SerializeList"/>
...

<service name="logview">
  <inbound>
    <http:inbound-endpoint host="localhost" port="8009" path="logview" synchronous="true"
      name="logview.http" keep-alive="false"  responseTransformer-refs="SerializeList xslt" />
  </inbound>
  <outbound>
    <chaining-router>
     <jdbc:outbound-endpoint connector-ref="DerbyConnector" queryKey="GETLOG" synchronous="true" />
    </chaining-router>
  </outbound>
</service>

Our application will receive the request at the url http://<host>:8009/logview. At this time a GETLOG query will be executed and the result will be Serialize by SerializeList transformation. At last Xslt transformation will be applied at the xml result.

I would avoid going too deeply in issue like Serialization or http connector. Probably they will be discussed in other posts.

Here the result

 

In this log you can see the Session of the flow, Correlate Session and endpoints.

Conclusion

In Enterprise edition of Mule ESB is available MMC (Mule Management Console). This is a good tool and supplies more features, in better way, about mule logging.

My solution is very Do-it-yourself and it has been developed in a very particular situation. I wanted to show my experience about Mule code customization.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s