当前位置: 首页 > news >正文

做日语网站网站seo优化技巧

做日语网站,网站seo优化技巧,百度推广优化怎么做的,网站建设_聊城Seata 是一款开源的分布式事务解决方案,致力于在微服务架构下提供高性能和简单易用的分布式事务服务。 官网:Apache Seata 文章目录 一、部署1.下载2.修改配置,nacos作注册中心,db存储 二、集成到springcloud项目1.引入依赖2.修改…

Seata 是一款开源的分布式事务解决方案,致力于在微服务架构下提供高性能和简单易用的分布式事务服务。

官网:Apache Seata

文章目录

  • 一、部署
    • 1.下载
    • 2.修改配置,nacos作注册中心,db存储
  • 二、集成到springcloud项目
    • 1.引入依赖
    • 2.修改配置
    • 3.新建数据表
    • 4.编写代码
    • 5.测试结果

一、部署

由于网络问题一直拉取docker镜像失败,所以这里采用了下载zip包直接部署的方式

版本说明 · alibaba/spring-cloud-alibaba Wiki · GitHub (需要和springcloud的版本对应)

1.下载

直接部署 | Apache Seata

上传服务器并解压

在这里插入图片描述

2.修改配置,nacos作注册中心,db存储

修改conf/application.yml

server:port: 7091spring:application:name: seata-serverlogging:config: classpath:logback-spring.xmlfile:path: ${user.home}/logs/seataextend:logstash-appender:destination: 192.168.100.52:4560kafka-appender:bootstrap-servers: 192.168.100.52:9092topic: logback_to_logstashconsole:user:username: seatapassword: seataseata:config:# support: nacos, consul, apollo, zk, etcd3type: nacosnacos:server-addr: 192.168.100.53:8848namespace: 17a4ea5e-f549-4e4a-97a4-52ee2a9f466cgroup: spmp-systemusername: nacospassword: nacosdata-id: seataServer.propertiesregistry:# support: nacos, eureka, redis, zk, consul, etcd3, sofatype: nacosnacos:application: seata-serverserver-addr: 192.168.100.53:8848group: spmp-systemnamespace: 17a4ea5e-f549-4e4a-97a4-52ee2a9f466c# tc集群名称cluster: defaultusername: nacospassword: nacos
#  server:
#    service-port: 8091 #If not configured, the default is '${server.port} + 1000'security:secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017tokenValidityInMilliseconds: 1800000ignore:urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

此时启动seata服务端,已经可以在nacos服务列表看到seata-server服务

cd bin
sh seata-seaver.sh

在这里插入图片描述

然后在nacos新建配置文件seataServer.properties

在这里插入图片描述

store.mode=db
store.db.dbType=mysql
store.db.datasource=druid
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://192.168.100.52:3306/seata?characterEncoding=UTF8&autoReconnect=true&serverTimezone=Asia/Shanghai
store.db.user=seata
store.db.password=seata

这里注意先建数据库seata,然后执行建表sql,脚本在script/server/db/下的mysql.sql

在这里插入图片描述

然后重启seata服务端

可以从seata启动日志 logs/start.out 看到读取配置的相关信息

在这里插入图片描述

二、集成到springcloud项目

这里我们拿项目里其中两个微服务来测试,如图所示,服务1被调用方服务2调用方

在这里插入图片描述

1.引入依赖

两个微服务的pom文件里都需要引入seata依赖

<dependency><groupId>io.seata</groupId><artifactId>seata-spring-boot-starter</artifactId><version>1.6.1</version>
</dependency>
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-seata</artifactId><version>2021.0.5.0</version><exclusions><exclusion><groupId>io.seata</groupId><artifactId>seata-spring-boot-starter</artifactId></exclusion></exclusions>
</dependency>

2.修改配置

修改两个微服务的配置文件,这里对应上前面seata服务端的配置

seata:registry:type: nacosnacos:application: seata-serverserver-addr: 192.168.100.53:8848group: spmp-systemnamespace: 17a4ea5e-f549-4e4a-97a4-52ee2a9f466cusername: nacospassword: nacosconfig:type: nacosnacos:server-addr: 192.168.100.53:8848group: spmp-systemnamespace: 17a4ea5e-f549-4e4a-97a4-52ee2a9f466cdataId: seataServer.propertiesusername: nacospassword: nacostx-service-group: spmp-system

3.新建数据表

两个服务都需要新建undo_log表,在事务回滚时需要用到,建表sql:

CREATE TABLE `undo_log` (`id` bigint(20) NOT NULL AUTO_INCREMENT,`branch_id` bigint(20) NOT NULL,`xid` varchar(100) NOT NULL,`context` varchar(128) NOT NULL,`rollback_info` longblob NOT NULL,`log_status` int(11) NOT NULL,`log_created` datetime NOT NULL,`log_modified` datetime NOT NULL,`ext` varchar(100) DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

4.编写代码

  • 修改全局异常处理器GlobalExceptionHandler

    由于项目里的全局处理器通常都会将所有异常拦截,然后返回统一封装结果,而这会导致异常无法抛出

    /*** 全局异常处理器** @author ruoyi*/
    @RestControllerAdvice
    public class GlobalExceptionHandler {private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);/*** 先判断是否是seata全局事务异常,如果是,就直接抛给调用方,让调用方回滚事务* @param e* @throws Exception*/private void checkSeataError(Exception e) throws Exception {log.info("seata全局事务ID: {}", RootContext.getXID());// 如果是在一次全局事务里出异常了,就不要包装返回值,将异常抛给调用方,让调用方回滚事务if (StrUtil.isNotBlank(RootContext.getXID())) {throw e;}}/*** 请求方式不支持*/@ExceptionHandler(HttpRequestMethodNotSupportedException.class)public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request) throws Exception {checkSeataError(e);String requestUri = request.getRequestURI();log.error("请求地址'{}',不支持'{}'请求", requestUri, e.getMethod());return AjaxResult.error(e.getMessage());}/*** 业务异常*/@ExceptionHandler(ServiceException.class)public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) throws Exception {checkSeataError(e);log.error(e.getMessage(), e);Integer code = e.getCode();return StringUtils.isNotNull(code) ? AjaxResult.error(code, StrUtil.isEmpty(e.getMessage()) ? e.getCause().getMessage() : e.getMessage()) : AjaxResult.error(StrUtil.isEmpty(e.getMessage()) ? e.getCause().getMessage() : e.getMessage());}/*** 请求参数类型不匹配*/@ExceptionHandler(MethodArgumentTypeMismatchException.class)public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) throws Exception {checkSeataError(e);String requestUri = request.getRequestURI();String value = Convert.toStr(e.getValue());if (StringUtils.isNotEmpty(value)) {value = EscapeUtil.clean(value);}log.error("请求参数类型不匹配'{}',发生系统异常.", requestUri, e);return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), value));}/*** 切面异常统一捕获*/@ExceptionHandler(AspectException.class)public ResponseResult<?> handleAspectException(AspectException aspectException) {aspectException.printStackTrace();return ResponseResult.error(aspectException.getResultStatus(), null);}/*** 系统基类异常捕获*/@ExceptionHandler(BasesException.class)public ResponseResult<?> handleBasesException(BasesException basesException) throws Exception {checkSeataError(basesException);basesException.printStackTrace();return ResponseResult.error(basesException.getResultStatus(), null);}/*** 拦截未知的运行时异常*/@ExceptionHandler(RuntimeException.class)public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) throws Exception {checkSeataError(e);String requestUri = request.getRequestURI();log.error("请求地址'{}',发生未知异常.", requestUri, e);return AjaxResult.error(e.getMessage());}/*** 系统异常*/@ExceptionHandler(Exception.class)public AjaxResult handleException(Exception e, HttpServletRequest request) throws Exception {checkSeataError(e);String requestUri = request.getRequestURI();log.error("请求地址'{}',发生系统异常.", requestUri, e);return AjaxResult.error(e.getMessage());}/*** 自定义验证异常*/@ExceptionHandler(BindException.class)public AjaxResult handleBindException(BindException e) throws Exception {checkSeataError(e);log.error(e.getMessage(), e);String message = e.getAllErrors().get(0).getDefaultMessage();return AjaxResult.error(message);}/*** 自定义验证异常*/@ExceptionHandler(MethodArgumentNotValidException.class)public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) throws Exception {checkSeataError(e);log.error(e.getMessage(), e);String message = e.getBindingResult().getFieldError().getDefaultMessage();return ResponseResult.error(message);}/*** 内部认证异常*/@ExceptionHandler(InnerAuthException.class)public AjaxResult handleInnerAuthException(InnerAuthException e) throws Exception {checkSeataError(e);return AjaxResult.error(e.getMessage());}......
    }
    
  • 修改Feign熔断降级方法

    由于项目对远程调用接口还做了熔断降级操作,导致调用方仍然识别不到异常,所以这里将熔断降级方法修改下,让其能正常抛异常

    @Component
    @Slf4j
    public class ConstructionProviderFallback implements IConstructionProvider {@Overridepublic ResponseResult<String> testSeata(Boolean error) {if (error) {throw new RuntimeException("降级方法中---模拟被调用方异常");}return ResponseResult.success("----------------testSeata接口远程调用熔断-----------------");}
    }
    
  • 启动类增加AOP注解

    由于全局事务注解@GlobalTransactional底层是基于AOP实现,所以需要给两个服务的启动类都加上AOP注解

    @EnableAspectJAutoProxy(exposeProxy = true, proxyTargetClass = true)

  • 调用方测试接口

    /*** 测试全局事务* @return*/
    @ApiOperation("测试全局事务")
    @GetMapping("/testSeata")
    @ApiImplicitParam(name = "type", value = "1:模拟调用方异常 其他:模拟被调用方异常")
    public ResponseResult<Boolean> testSeata(@RequestParam Integer type) {SecurityTest securityTest = new SecurityTest();securityTest.setTestColumn("测试全局事务");securityTest.setOrganizeId(1L);return ResponseResult.success(testSeataService.testSeata(type,securityTest));
    }
    
    @GlobalTransactional
    @Override
    public Boolean testSeata(Integer type, SecurityTest securityTest) {log.info("seata全局事务ID: {}", RootContext.getXID());if (type!=null&&type==1) {//先远程调用construction服务保存远程服务数据constructionProvider.testSeata(false);//再保存自己服务数据securityTestService.save(securityTest);//模拟调用方异常throw new RuntimeException("模拟调用方异常");} else {//先保存自己服务数据securityTestService.save(securityTest);//再远程调用construction服务保存远程服务数据,且模拟被调用方异常constructionProvider.testSeata(true);}return true;
    }
    

    这里测试两种情况,调用方异常事务回滚,还有被调用方异常事务回滚

  • 被调用方提供的Feign接口

    @Service(value = "IConstructionProvider")
    @FeignClient(value = ConstructionProviderConstant.MATE_CLOUD_CONSTRUCTION, fallback = ConstructionProviderFallback.class)
    public interface IConstructionProvider {/*** 测试全局事务* @param error* @return*/@GetMapping(ConstructionProviderConstant.TEST_SEATA)ResponseResult<String> testSeata(@RequestParam("error") Boolean error);}
    

    这里当时遇到了一个坑

    • 如果不写@RequestParam(“error”) ,会识别成POST请求,然后报错不支持POST请求

    • 如果写了@RequestParam,但是没设置value属性,即写@RequestParam Boolean error,也会报错

      参考:Feign 调用报 RequestParam.value() was empty on parameter 0-CSDN博客

    实现:

    在这里插入图片描述

    正常调用:

    /*** 测试Seata全局事务* @param error 是否模拟被调用方异常* @return*/
    @Override
    @ApiOperation(value = "测试Seata全局事务", notes = "测试Seata全局事务", httpMethod = "GET")
    @GetMapping(ConstructionProviderConstant.TEST_SEATA)
    @SentinelResource(value = ConstructionProviderConstant.TEST_SEATA, fallbackClass = ConstructionProviderFallback.class, fallback = "testFeign")
    public ResponseResult<String> testSeata(@RequestParam(value = "error") Boolean error) {SecurityTest1 test = new SecurityTest1();test.setTestColumn("seata");test.setOrganizeId(1L);securityTestService.save(test);if (error) {throw new RuntimeException("模拟被调用方异常");}return ResponseResult.success("---------------testSeata接口正常------------------");
    }
    

    熔断降级:

    @Override
    public ResponseResult<String> testSeata(Boolean error) {if (error) {throw new RuntimeException("降级方法中---模拟被调用方异常");}return ResponseResult.success("----------------testSeata接口远程调用熔断-----------------");
    }
    

5.测试结果

分别测试了调用方异常、被调用方异常的情况,均能实现全局事务回滚(两边的数据库都回滚了),如下图所示

在这里插入图片描述

在这里插入图片描述

下面是seata控制台的信息(存于数据库里)

在这里插入图片描述

这里我测试的结果是 只有调用方和被调用方都有事务回滚 才会有信息,而且会定期清除


文章转载自:
http://cardiganshire.rsnd.cn
http://tex.rsnd.cn
http://cumulus.rsnd.cn
http://fieldwork.rsnd.cn
http://siphon.rsnd.cn
http://concoct.rsnd.cn
http://habitable.rsnd.cn
http://miserere.rsnd.cn
http://cordate.rsnd.cn
http://svizzera.rsnd.cn
http://smooth.rsnd.cn
http://slinger.rsnd.cn
http://spindleful.rsnd.cn
http://ammocete.rsnd.cn
http://geosynchronous.rsnd.cn
http://twinge.rsnd.cn
http://fugal.rsnd.cn
http://hurt.rsnd.cn
http://japanism.rsnd.cn
http://radii.rsnd.cn
http://dilator.rsnd.cn
http://devious.rsnd.cn
http://trawl.rsnd.cn
http://dodecaphonist.rsnd.cn
http://dropper.rsnd.cn
http://papillon.rsnd.cn
http://corrigent.rsnd.cn
http://slote.rsnd.cn
http://christabel.rsnd.cn
http://preconscious.rsnd.cn
http://amoy.rsnd.cn
http://shotfire.rsnd.cn
http://chromoplasmic.rsnd.cn
http://alchemistically.rsnd.cn
http://eloge.rsnd.cn
http://pod.rsnd.cn
http://librarian.rsnd.cn
http://filtration.rsnd.cn
http://toccata.rsnd.cn
http://sarajevo.rsnd.cn
http://kickplate.rsnd.cn
http://southampton.rsnd.cn
http://neuropsychology.rsnd.cn
http://hydroperoxide.rsnd.cn
http://wanking.rsnd.cn
http://sup.rsnd.cn
http://geewhillikins.rsnd.cn
http://euclidian.rsnd.cn
http://faggoting.rsnd.cn
http://rnwmp.rsnd.cn
http://cinquefoil.rsnd.cn
http://destocking.rsnd.cn
http://torino.rsnd.cn
http://revises.rsnd.cn
http://spectrometer.rsnd.cn
http://blandish.rsnd.cn
http://hypsicephalous.rsnd.cn
http://windcheater.rsnd.cn
http://heterotrophic.rsnd.cn
http://wisha.rsnd.cn
http://cayman.rsnd.cn
http://outbuild.rsnd.cn
http://postproduction.rsnd.cn
http://schist.rsnd.cn
http://demanding.rsnd.cn
http://gunpoint.rsnd.cn
http://cellblock.rsnd.cn
http://klepto.rsnd.cn
http://electroshock.rsnd.cn
http://tenorist.rsnd.cn
http://trendy.rsnd.cn
http://gefuffle.rsnd.cn
http://fervour.rsnd.cn
http://stackup.rsnd.cn
http://ecad.rsnd.cn
http://notornis.rsnd.cn
http://plp.rsnd.cn
http://creditably.rsnd.cn
http://anaerobium.rsnd.cn
http://amidol.rsnd.cn
http://quinquecentennial.rsnd.cn
http://immunohistochemical.rsnd.cn
http://redry.rsnd.cn
http://broncho.rsnd.cn
http://mfn.rsnd.cn
http://devisee.rsnd.cn
http://catalo.rsnd.cn
http://neckpiece.rsnd.cn
http://jdisplay.rsnd.cn
http://malleolus.rsnd.cn
http://moore.rsnd.cn
http://witless.rsnd.cn
http://puristical.rsnd.cn
http://miniplanet.rsnd.cn
http://delegatee.rsnd.cn
http://semicircular.rsnd.cn
http://bannerette.rsnd.cn
http://gradgrind.rsnd.cn
http://ferro.rsnd.cn
http://burnt.rsnd.cn
http://www.15wanjia.com/news/82629.html

相关文章:

  • 网站开发外包费用的会计分录重庆百度关键词推广
  • 怎么在一个网站做编辑今日新闻国际头条新闻
  • 小程序api开发小红书怎么做关键词排名优化
  • wordpress模板如何修改seo推广方式是什么呢
  • fedora做网站服务器快速优化seo软件推广方法
  • 华为云怎么做网站如何提高网站排名seo
  • 做兼职做网站的是什么竞价销售是什么意思
  • 科技公司网站设计风格廊坊seo
  • nas怎么做网站服务器开电商需要多少钱
  • 武汉大型网站开发百度搜索资源
  • 投资理财产品的网站建设windows优化大师值得买吗
  • 高端网站建设企业官网建设app推广渠道
  • 企业门户网站国内外研究现状百度app下载官方
  • 中央经济工作会议2023年7月召开seo排名优化培训价格
  • 北海公司做网站seo优化方案
  • 初中生做网站挣钱湖南seo服务
  • 荣成市信用建设网站怎么发外链
  • 外包服务商南宁白帽seo技术
  • 证券网站怎么做网上推广app
  • 莆田哪里有网站开发百度小程序入口
  • 苏州建站模板厂家如何免费注册一个网站
  • 免费 企业网站管理系统郑州竞价托管
  • 公众号设计平台关键词优化公司推荐
  • asp网站无法上传图片优化推广网站淄博
  • 手机网站 app丈哥seo博客工具
  • 中卫网站建设市场推广计划方案模板
  • 网站认证打的钱怎么做分录网站排名查询工具有哪些
  • 网站开发与维护 专业网站制作论文
  • 深圳浪尖工业设计公司搜索引擎优化趋势
  • 网站搜索页面怎么做零基础能做网络推广吗