2024-踩坑记录

Redis set问题- 2024-11-15

手动修改用户信息再设值时,报-ERR wrong number of arguments for ‘set’ command,值是json对象的字符串,以为是要转义,转义后也不行,给值加上单引号,双引号也都不行。

最后解决是给key 加了过期时间 ex 7776000 可以了。这个应该是redis服务端设值的必须加过期时间。

get *

set * ‘上面get的值’ EX 7776000

如何找到token

“*-19176570” AND “/user/api/query”

RestTemplate序列化问题- 2024-05-30

发送飞书通知时,没有注入restTemplate,发送飞书成功,但会抛一个异常。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
异常信息:Unexpected exception occurred invoking async method: public com.*.order.user.web.pojo.pojo.BotMessageResult com.*.order.user.web.service.impl.FeiShuServiceImpl.sendAlertMessageByModel(com.*.order.user.web.pojo.pojo.FeiShuStockAlertModel)
服务名称:*-order-user-web
Pod: *-order-user-web-deployment-feature-refund-order-6f7ffdrcpwn
Container: *-order-user-web
Namespace: class
IP:172.16.16.17
发生时间:2024-05-29 19:20:08
请求类型:
跟踪traceId:bee0670551ec8dd4
源:
异常信息:I/O error on POST request for "http://zeus.corp.*.club/portal/prod/api/notification/sendWebhook/23": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out
异常堆栈:
`org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://zeus.corp.*.club/portal/prod/api/notification/sendWebhook/23": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:746)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:672)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:581)
at com.*.order.user.web.service.impl.FeiShuServiceImpl.sendBotMessage(FeiShuServiceImpl.java:55)
at com.*.order.user.web.service.impl.FeiShuServiceImpl.sendAlertMessageByModel(FeiShuServiceImpl.java:77)
at com.*.order.user.web.service.impl.FeiShuServiceImpl$$FastClassBySpringCGLIB$$c152dde3.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
at io.opentracing.contrib.spring.cloud.async.TraceAsyncAspect.traceBackgroundThread(TraceAsyncAspect.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)`

需要在项目中显示注入restTemplate,如下,解决问题

1
2
3
4
5
6
7
8
9
@Configuration
public class RestTemplateConfig {

@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}

}

镜像问题- 2024-04-16

*-order-crm-web 本地部署成功,dev环境部署不成功,一直重启。

一直在看应用日志,没有error,看不出原因。

后来问了,是镜像问题,要切到docker看原始日志,原始日志有报错。

加了pulsar,要修改镜像。

*-pro-image.tencentcloudcr.com/library/openjdk8:alpine-ziti

*-pro-image.tencentcloudcr.com/library/openjdk8:alpine-slim

Feign序列化问题- 2024-04-03

*-goods-crm-web 调用 -third-server,旺店通。先发现入参通过-goods-crem-web,有值,通过调用 *-third-server就没有值了,都是一个对象。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class WdtSingleGoodsQueryParam extends WdtBaseParam {
/**
* 商家编码,代表单品(SKU)所有属性的唯一编码,用于获取指定的系统单品的数据
*/
@JSONField(name = "spec_no")
private String specNo;

/**
* 货品编号,代表货品(SPU)所有属性的唯一编号,用于指定获取系统货品的数据
*/
@JSONField(name = "goods_no")
private String goodsNo;

/**
* 品牌编号
*/
@JSONField(name = "brand_no")
private String brandNo;

/**
* 分类名称
*/
@JSONField(name = "class_name")
private String className;

/**
* 条码
*/
@JSONField(name = "barcode")
private String barcode;

/**
* 开始时间,按最后修改时间增量查询数据,startTime作为开始时间,格式:yyyy-MM-dd HH:mm:ss
* 必传,与endTime时间跨度最大30天
*/
@JSONField(name = "start_time", format = "yyyy-MM-dd HH:mm:ss")
private Date startTime;

/**
* 结束时间,按最后修改时间增量查询数据,endTime作为结束时间,格式:yyyy-MM-dd HH:mm:ss
* 必传,与startTime时间跨度最大30天
*/
@JSONField(name = "end_time", format = "yyyy-MM-dd HH:mm:ss")
private Date endTime;

/**
* 已删除货品,默认为0, 0:只返回未删除货品 1:返回未删除和已删除货品
*/
@JSONField(name = "deleted")
private Integer deleted;

/**
* 分页大小,每页返回的数据条数,输入值范围1~100,不传本参数,输入值默认为40
*/
@JSONField(name = "page_size")
private Integer pageSize;

/**
* 页号,不传默认从0页开始
*/
@JSONField(name = "page_no")
private Integer pageNo;

然后检查*-goods-crm-web的feign序列化配置,使用的是fastjson

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@Bean
public Encoder feignEncoder() {
return new SpringEncoder(feignHttpMessageConverter());
}

@Bean
public Decoder feignDecoder() {
return new SpringDecoder(feignHttpMessageConverter());
}
/**
* 设置解码器为fastjson
*
* @return
*/
private ObjectFactory<HttpMessageConverters> feignHttpMessageConverter() {
final HttpMessageConverters httpMessageConverters = new HttpMessageConverters(this.getFastJsonConverter());
return () -> httpMessageConverters;
}

private FastJsonHttpMessageConverter getFastJsonConverter() {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();

List<MediaType> supportedMediaTypes = new ArrayList<>();
MediaType mediaTypeJson = MediaType.valueOf(MediaType.APPLICATION_JSON_UTF8_VALUE);
supportedMediaTypes.add(mediaTypeJson);
converter.setSupportedMediaTypes(supportedMediaTypes);
FastJsonConfig config = new FastJsonConfig();
config.getSerializeConfig().put(JSON.class, new SwaggerJsonSerializer());
config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
converter.setFastJsonConfig(config);

return converter;
}

反序列化的问题,改成如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class JacksonFeignConfig {

@Bean
public Encoder jacksonEncoder() {
return new CustomJacksonEncoder();
}

public static class CustomJacksonEncoder extends JacksonEncoder {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
super.encode(object, bodyType, template);
template.header("Content-Type", "application/json");
}
}

@Bean
public Decoder jacksonDecoder() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return new JacksonDecoder(objectMapper);
}

}

调用旺店通的client

1
2
3
@FeignClient(value = "*-third-server", contextId = "wdtClient", configuration = JacksonFeignConfig.class)
public interface WdtClient extends WdtApi {
}

因为*-third-server 调用旺店通使用的是fastjson 序列化,然后*-third-client 偷了个懒,共用param,result。*-goods-crm-web有用的fastjson序列化,针对 @JSONField(name = “start_time”, format = “yyyy-MM-dd HH:mm:ss”),JSONField注解反序列化就有问题。

出参也是一样的问题,但出参遇到日期格式化问题,解决如下:

1
2
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

服务监控检查慢- 2024-03-15

Springboot actuator 禁用邮件健康检查

服务使用了邮件功能,关闭邮件的监控检查

1
2
3
4
management:
health:
mail:
enabled: false

powerjob集成客户端心跳报错- 2024-01-10

客户库集成后报错如下:

心跳的协议用的是http

1
t.p.r.http.vertx.VertxTransporter [VertxTransporter] post to url[URL(serverType=SERVER, address=172.31.110.9:10010, location=HandlerLocation(rootPath=server, methodPath=workerHeartbeat))] failed,msg: NoClassDefFoundError: Could not initialize class io.vertx.core.http.HttpHeaders  "}

解决步骤如下:

command + o 搜索 io.vertx.core.http.HttpHeaders 这个类,下载源码,发现有红线报错。找到报错地方,显示应用如下依赖

1
2
3
4
5
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-codegen</artifactId>
<version>4.3.7</version>
</dependency>

启动后还是报错,

下载powerjob源码 发现 netty相关版本是4.1.86.Final,但项目中netty版本是4.1.53.Final

在项目中统一netty版本如下

1
2
3
4
5
6
7
8
9
10
11
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-bom</artifactId>
<version>4.1.86.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

解决问题