10.1.1 Enable Session Affinity

When you enable session affinity, all the requests for a unique transaction or session are routed to the same endpoint or replica of the participant service that served the first request.

Use the instructions provided in this section to enable session affinity or sticky sessions if you have deployed the participant service or transaction coordinator within an Istio service mesh. The steps provided in this section are specific to enabling session affinity for a participant service. You can enable session affinity for the transaction coordinator in a similar manner. To enable session affinity for the transaction coordinator, update the YAML files and Helm Chart that are specific to the transaction coordinator.
Before you begin, complete the following tasks:
  1. Ensure that you have deployed the transaction participant service within an Istio service mesh.
  2. Identify if you need to enable session affinity for your participant service or for the transaction coordinator. See About Session Affinity.
To enable session affinity for a participant service:
  1. Create a networking rule for the application in the namespace where you want to deploy it. The traffic policy must use a load balancer with consistent hash that uses the HTTP request header, oracle-tmm-txn-id.
  2. In the Helm Chart of the participant application, specify the oracle-tmm-txn-id HTTP header in Istio's DestinationRule resource. Use a load balancer that is based on consistent hash to provide session affinity based on the oracle-tmm-txn-id HTTP header.
    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
        name: sticky-participant
        namespace: otmm
    spec:
        host: sticky-participant.otmm.svc.cluster.local
        trafficPolicy:
          loadBalancer:
            consistentHash:
              httpHeaderName: oracle-tmm-txn-id

    Where,

    • sticky-participant is the name of the participant application.
    • otmm is the namespace in which you want to deploy your participant application.
    • host: Specify the fully qualified name of your application inside the Kubernetes cluster. For example, dept1.otmm.svc.cluster.local.

  3. In the values.yaml file of the participant service, add the following line of code:
    sessionAffinity: true
  4. In the networking.yaml file of the participant service, add the following lines of code:
    spec:
        host: {{$val.host}}
        trafficPolicy:
          loadBalancer:
            consistentHash:
              httpHeaderName: oracle-tmm-txn-id