尝试使用 mysql 而不是 h2 来遵循 [1]。但是,在事务块之间添加它时似乎存在问题。在 bre/lib 文件夹下包含了 mysql lib。以下是端点定义和事务块。在创建表后运行 .bal 文件时,会启动事务,但随后会直接重试事务并最终中止它。知道这里缺少什么吗?[1] https://ballerina.io/learn/by-example/xa-transactions.html
endpoint mysql:Client testDB1 {
host: "localhost",
port: 3306,
name: "customerdb",
username: "root",
password: "root",
poolOptions: { maximumPoolSize: 5, isXA:true },
dbOptions: { useSSL: false }
};
endpoint mysql:Client testDB2 {
host: "localhost",
port: 3306,
name: "salarydb",
username: "root",
password: "root",
poolOptions: { maximumPoolSize: 5, isXA:true },
dbOptions: { useSSL: false }
};
transaction with retries = 3, oncommit = onCommitFunction, onabort = onAbortFunction {
var retWithKey = testDB1->updateWithGeneratedKeys("INSERT INTO
CUSTOMER(NAME) VALUES ('Anne')", ());
string generatedKey;
match retWithKey {
(int, string[]) y => {
var (count, ids) = y;
generatedKey = ids[0];
io:println("Inserted row count: " + count);
io:println("Generated key: " + generatedKey);
}
error err => io:println("Insert to customer table failed: "
+ err.message);
}
ret = <int>generatedKey;
int key = -1;
match ret {
int retInt => key = retInt;
error err => io:println("Converting key to string failed: "
+ err.message);
}
io:println("Generated key for the inserted row: " + key);
ret = testDB2->update("INSERT INTO SALARY (ID, VALUE)
VALUES (?, ?)", key, 2500);
handleUpdate(ret, "Insert to SALARY table");
} onretry {
io:println("Retrying transaction");
}