Sharding-Proxy 如何集成分布式事务 Seata

Sharding-Proxy 集成分布式事务 Seata 的大致步骤…

  1. 首先我们根据 ss 官方文档安装好 Seata 的服务端. Seata 事务 :: ShardingSphere

启动成功的截图:

  1. 下载 :: ShardingSphere , 从官网下载最新的 Sharding-Proxy 的安装包 (同学们可以解压到远端服务器, 也可以在本地进行解压), 我采用的是 mac 系统本地环境

  2. 完成步骤2之后, 我们进入解压好的文件(这里我起个别叫 proxy, 后面我提到 proxy 就代表我说的是解压好的文件), 并找到 /config/server.yaml 文件, 根据实际需求修改里面的配置, 需要注意的是, 我们需要将下面的配置更换成:

 - !TRANSACTION
   defaultType: BASE
   providerType: Seata
  1. 将 Seata 的三个文件: file.conf、registry.conf、seata.conf, 放入 proxy (别名、指的是解压好的文件) 文件, 注意: 跟 bin、conf、lib、licenses 同级的目录哦.

  1. proxy/lib 文件下, 我们需要新增几个 seata 需要的 jar 包, 以及删除几个我们不需要的jar包(一定要删除哦)
  • 将 /proxy/lib 下面有关于 xa 的 jar 包全部删掉, 只要 jar 的名字包含 xa, 一律干掉.

  • /proxy/lib 下面新增一些jar包:

commons-pool-1.5.1.jar
seata-all-1.4.2.jar
shardingsphere-transaction-base-seata-at-5.0.1-SNAPSHOT.jar
cglib-3.1.jar
commons-dbcp2-2.8.0.jar

注意 : 上面新增的 jar 包可能不全, 因为我也不太记得加了几个 jar 了, 不过我们在启动 Sharding-Proxy 的时候可以看下日志, 如果报 Caused by: java.lang.ClassNotFoundException: 类型这样的错误, 我们只需要从 maven 仓库中去找下对应的 jar 包下载下来, 放入 /proxy/lib 下就可以了.

  1. 完成上面的5个步骤, 基本上就完成了前期准备工作, 下面让我们来真正的启动 Sharding-Proxy 吧!

Sharding-Proxy 启动成功的截图:

3 个赞

哇哦!真是太棒了,学到了~ :muscle:

能否把你的 proxy 文件打成一个压缩包上传上来.

我已经按照:ShardingSphere-Proxy Base 事务基于 Seata 验证 来配置,现在错误不一样了,相关shardingshpere的包已经重新上传:
百度网盘 请输入提取码
提取码:z3y8

错误信息:

[INFO ] 2021-12-29 14:43:17.808 [main] io.seata.config.FileConfiguration - The file name of the operation is seata.conf
[INFO ] 2021-12-29 14:43:17.814 [main] io.seata.config.FileConfiguration - The configuration file used is seata.conf
[INFO ] 2021-12-29 14:43:17.916 [main] io.seata.config.FileConfiguration - The file name of the operation is seata.conf
[INFO ] 2021-12-29 14:43:17.917 [main] io.seata.config.FileConfiguration - The configuration file used is seata.conf
[INFO ] 2021-12-29 14:43:17.943 [main] io.seata.config.FileConfiguration - The file name of the operation is registry
[INFO ] 2021-12-29 14:43:17.943 [main] io.seata.config.FileConfiguration - The configuration file used is registry.conf
Exception in thread “main” java.lang.NoClassDefFoundError: com/alibaba/nacos/api/exception/NacosException
at io.seata.config.nacos.NacosConfigurationProvider.provide(NacosConfigurationProvider.java:29)
at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:131)
at io.seata.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:94)
at io.seata.core.rpc.netty.NettyBaseConfig.(NettyBaseConfig.java:54)
at io.seata.core.rpc.netty.TmNettyRemotingClient.getInstance(TmNettyRemotingClient.java:113)
at io.seata.core.rpc.netty.TmNettyRemotingClient.getInstance(TmNettyRemotingClient.java:96)
at io.seata.tm.TMClient.init(TMClient.java:46)
at io.seata.tm.TMClient.init(TMClient.java:34)
at org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager.initSeataRPCClient(SeataATShardingSphereTransactionManager.java:78)
at org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager.init(SeataATShardingSphereTransactionManager.java:71)
at org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine.lambda$init$0(ShardingSphereTransactionManagerEngine.java:71)
at java.util.Map.forEach(Map.java:630)
at org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine.init(ShardingSphereTransactionManagerEngine.java:71)
at org.apache.shardingsphere.transaction.context.TransactionContextsBuilder.build(TransactionContextsBuilder.java:54)
at org.apache.shardingsphere.mode.manager.memory.MemoryContextManagerBuilder.build(MemoryContextManagerBuilder.java:52)
at org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.initContext(BootstrapInitializer.java:76)
at org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.init(BootstrapInitializer.java:67)
at org.apache.shardingsphere.proxy.Bootstrap.main(Bootstrap.java:47)
Caused by: java.lang.ClassNotFoundException: com.alibaba.nacos.api.exception.NacosException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

这个百度云链接不存在了.

非常抱歉,可能更新文件了。
链接: 百度网盘 请输入提取码
提取码: d5x5

您没有根据这个配置吗? Sharding-Proxy 如何集成分布式事务 Seata

链接: 百度网盘 请输入提取码 提取码: 1wmg 请参考下这个 demo

已经把你的Demo下载了,可以正常运行,但是你这个是本地file配置,而我的是nacos,我把你的lib的文件进行全部替换,只不过就是file.conf和registry.conf替换成了nacos,无法启动,错误日志:

[INFO ] 2021-12-29 14:43:17.808 [main] io.seata.config.FileConfiguration - The file name of the operation is seata.conf
[INFO ] 2021-12-29 14:43:17.814 [main] io.seata.config.FileConfiguration - The configuration file used is seata.conf
[INFO ] 2021-12-29 14:43:17.916 [main] io.seata.config.FileConfiguration - The file name of the operation is seata.conf
[INFO ] 2021-12-29 14:43:17.917 [main] io.seata.config.FileConfiguration - The configuration file used is seata.conf
[INFO ] 2021-12-29 14:43:17.943 [main] io.seata.config.FileConfiguration - The file name of the operation is registry
[INFO ] 2021-12-29 14:43:17.943 [main] io.seata.config.FileConfiguration - The configuration file used is registry.conf
Exception in thread “main” java.lang.NoClassDefFoundError: com/alibaba/nacos/api/exception/NacosException
at io.seata.config.nacos.NacosConfigurationProvider.provide(NacosConfigurationProvider.java:29)
at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:131)
at io.seata.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:94)
at io.seata.core.rpc.netty.NettyBaseConfig.(NettyBaseConfig.java:54)
at io.seata.core.rpc.netty.TmNettyRemotingClient.getInstance(TmNettyRemotingClient.java:113)
at io.seata.core.rpc.netty.TmNettyRemotingClient.getInstance(TmNettyRemotingClient.java:96)
at io.seata.tm.TMClient.init(TMClient.java:46)
at io.seata.tm.TMClient.init(TMClient.java:34)
at org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager.initSeataRPCClient(SeataATShardingSphereTransactionManager.java:78)
at org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager.init(SeataATShardingSphereTransactionManager.java:71)
at org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine.lambda$init$0(ShardingSphereTransactionManagerEngine.java:71)
at java.util.Map.forEach(Map.java:630)
at org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine.init(ShardingSphereTransactionManagerEngine.java:71)
at org.apache.shardingsphere.transaction.context.TransactionContextsBuilder.build(TransactionContextsBuilder.java:54)
at org.apache.shardingsphere.mode.manager.memory.MemoryContextManagerBuilder.build(MemoryContextManagerBuilder.java:52)
at org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.initContext(BootstrapInitializer.java:76)
at org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.init(BootstrapInitializer.java:67)
at org.apache.shardingsphere.proxy.Bootstrap.main(Bootstrap.java:47)
Caused by: java.lang.ClassNotFoundException: com.alibaba.nacos.api.exception.NacosException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

或许缺少了 jar 包? 可以自行百度看下.

连接失效了能再提供一个么?

京ICP备2021015875号