Using Mule session properties

July 22 2011

2 comments 0
motif

Do you want share properties between mule instances? or just between different flows within Mule?. Then mule session properties are what you are looking for.

How to add session properties

The easier way is through Mule MessagePropertyTransformer:

You can also accede Mule session using MuleEventContext:

Considerations using Mule session properties

  • Mule session is transmitted with each external call so don’t store stuff that you don’t need to avoid draining i/o performance
  • Mule session is maintained while the Message is going through mule instances so don’t store stuff you don’t need to avoid wasting memory
  • Only java.io.Serializable objects will be transmitted between two flows
  • Currently if you add a non Serializable session property you will lose it after calling another flow. Since Mule 3.1.3 there’s a new merging strategy for session properties that will avoid losing them
  • When using http endpoints Mule session is stored as a custom http header so there are some limitations in header size. HTTP specification does not limit length of headers at all. However web-servers do limit header size they accept, throwing “413 Entity Too Large” if it exceeds or you can also get a java.io.SocketException: Broken Pipe in the client side
  • If you call an outbound endpoint with message exchange pattern one way, then the called flow will be able to access session properties, but modifications to session properties inside that flow will not be reflected in the caller flow
  • Don’t stick with Mule session scope every time. Try to use the best Mule property scope that suits your requirements

We'd love to hear your opinion on this post

2 Responses to “Using Mule session properties”

  1. Why is the HTTP connector setting these properties in the header? This should at a minimum be a configurable setting.

    Agree(0)Disagree(0)Comment
  2. Ok, this is just plain frustrating.

    Why are you showing us how to put a variable into the session, but not how to get it out again?

    Agree(1)Disagree(0)Comment