Define Sticky Routing Key

The sticky routing key can be defined based on many parameters such as the IP address, machine domain name, and so on. The StickyKey is populated from the <stickyRoutingKey> element tag in the transformation (XSLT) file.

Refer to Example XSLT File for StickyRoutingKey to define an XSLT file for the sticky routing key.

Example XSLT File for StickyRoutingKey

The following example illustrates an XSLT file to derive a StickyRouting Key. Refer to the <stickyRoutingKey> element tag in the file defined as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:c="http://www.tibco.com/schemas/asg/context"
xmlns:h="http://www.tibco.com/asg/protocols/http"
xmlns:f="http://www.tibco.com/asg/functions/form"
xmlns:form="http://www.tibco.com/asg/content-types/form"
xmlns:book="http://www.example.com/xsd/books"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:output
omit-xml-declaration="yes"
indent="yes"
/>
<xsl:variable name="contextHref">
<xsl:value-of select="/transformation/context/@href"/>
</xsl:variable>
<xsl:variable name="httpRequest">
<xsl:copy-of select="document($contextHref)/c:context/c:entry[@key='asg:httpRequest']/h:request/*"/>
</xsl:variable>
<xsl:variable name="parsedQueryString">
<xsl:value-of select="$httpRequest/h:client-ip"/>
</xsl:variable>
<xsl:variable name="nbRequestHref">
<xsl:value-of select="/transformation/nbRequest/@href"/>
</xsl:variable>
<xsl:variable name="nbRequest">
<xsl:copy-of select="document($nbRequestHref)/soapenv:Envelope/soapenv:Body/*"/>
</xsl:variable>
<xsl:template match="/">
<output>
<xsl:variable name="username">
<xsl:value-of select="$nbRequest/book:Author"/>
</xsl:variable>
<username><xsl:value-of select="$username"/></username>
<parsedQueryString><xsl:value-of select="$parsedQueryString"/></parsedQueryString>
<routingKey>
<xsl:choose>
<xsl:when test="$username = 'Vivek Ranadive'"><xsl:value-of select="$username"/></xsl:when>
<xsl:when test="$username = 'Vivek Ranadive1'"><xsl:value-of select="$username"/></xsl:when>
<xsl:when test="$username = 'Vivek Ranadive3'"><xsl:value-of select="$username"/></xsl:when>
<xsl:otherwise>default</xsl:otherwise>
</xsl:choose>
</routingKey>
<stickyRoutingKey>
<xsl:choose>
<xsl:when test="$parsedQueryString != ''"><xsl:value-of select="$parsedQueryString"/></xsl:when>
<xsl:otherwise>default</xsl:otherwise>
</xsl:choose>
</stickyRoutingKey>
</output>
</xsl:template>
</xsl:stylesheet>