9.3. 配置 Spring Boot Narayana 恢复控制器

以下示例演示了如何配置 Narayana 以使用恢复控制器在 OpenShift 上工作。

流程

  1. 这是一个 application.properties 文件示例。替换 Kubernetes yaml 描述符中的以下选项。

    # Cluster
    cluster.nodename=1
    cluster.base-dir=./target/tx
    
    # Transaction Data
    spring.jta.transaction-manager-id=${cluster.nodename}
    spring.jta.log-dir=${cluster.base-dir}/store/${cluster.nodename}
    
    # Narayana recovery settings
    snowdrop.narayana.openshift.recovery.enabled=true
    snowdrop.narayana.openshift.recovery.current-pod-name=${cluster.nodename}
    # You must enable resource filtering in order to inject the Maven artifactId
    snowdrop.narayana.openshift.recovery.statefulset=${project.artifactId}
    snowdrop.narayana.openshift.recovery.status-dir=${cluster.base-dir}/status
  2. 您需要一个共享卷来存储与终止相关的事务和信息。它可以挂载到 StatefulSet yaml 描述符中,如下所示。

    apiVersion: apps/v1beta1
    kind: StatefulSet
    #...
    spec:
    #...
      template:
    #...
        spec:
          containers:
          - env:
            - name: CLUSTER_BASE_DIR
              value: /var/transaction/data
              # Override CLUSTER_NODENAME with Kubernetes Downward API (to use `pod-0`, `pod-1` etc. as tx manager id)
            - name: CLUSTER_NODENAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
    #...
            volumeMounts:
            - mountPath: /var/transaction/data
              name: the-name-of-the-shared-volume
    #...

Camel 扩展 for Spring Boot Narayana Recovery Controller

如果在 Spring Boot 应用程序上下文中找到 Camel,则 Camel 上下文会在清除所有待处理的事务前自动停止。