There are use cases which we need to generate a UUID(universally unique identifier) from the WSO2 ESB server for the back end services. There are two commonly used UUID types,
- Version 1 UUID or Time UUID
- Version 4 UUID
Getting a version 4 UUID is really easy in ESB, since we already have one in the message flow. So we can extract it like follows,
<property name="MessageID" expression="fn:substring-after(get-property('MessageID'), 'urn:uuid:')"/>
But in case of version 1 UUID or Time UUID, we have to use script mediator or class mediator to generate a UUID. Script mediator is slower compared to the class mediator.
A simple class mediator which can use for version 1 UUID generation can be found here. This class mediator uses this library to generate UUID. After building this class mediator, copy "org.wso2.carbon.mediator.uuid-1.0.0.jar" and "java-uuid-generator-3.1.4.jar" to the <ESB_HOME>/repository/components/dropins folder.
You can access this class mediator as follows,
<class name="org.wso2.carbon.mediator.uuid.TimeUUIDGenMediator"/>
Generated UUID will be available in "uri.var.uuid" property and we can access it as follows,
<log level="custom">
<property name="Time-UUID" expression="$ctx:uri.var.uuid"/>
</log>
But in case of version 1 UUID or Time UUID, we have to use script mediator or class mediator to generate a UUID. Script mediator is slower compared to the class mediator.
A simple class mediator which can use for version 1 UUID generation can be found here. This class mediator uses this library to generate UUID. After building this class mediator, copy "org.wso2.carbon.mediator.uuid-1.0.0.jar" and "java-uuid-generator-3.1.4.jar" to the <ESB_HOME>/repository/components/dropins folder.
You can access this class mediator as follows,
<class name="org.wso2.carbon.mediator.uuid.TimeUUIDGenMediator"/>
Generated UUID will be available in "uri.var.uuid" property and we can access it as follows,
<log level="custom">
<property name="Time-UUID" expression="$ctx:uri.var.uuid"/>
</log>
Comments
Post a Comment