- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要修改 Spring Cloud AWS 在反序列化 JSON 时使用的 Jackson2 对象映射器并用它注册 JavaTime 模块。这是因为 SQS 有效负载包含必须使用 JavaTime 模块反序列化的 Java Instant 类的实例。
详细信息:
这是SQS监听器方法:
@SqsListener(value = "mysqs",deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void handleChangedEventFromSqsQueue(@NotificationMessage ChangeEvent event) {
try {
// Handle ChangeEvent object here
} catch (Throwable t) {
// Do something
}
}
这是 ChangedEvent 类:
public class ChangeEvent {
private final Long oldValue;
private final Long newValue;
private final Instant changedAt;
// This is the ID of the user who performed the change
private final Long changedBy;
// Constructors, getters, and setters omitted
}
这是我收到的错误:
org.springframework.messaging.MessagingException: An exception occurred while invoking the handler method; nested exception is org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Can not construct instance of java.time.Instant: no String-argument constructor/factory method to deserialize from String value ('2017-10-20T01:58:09.298Z')
at [Source: {"oldValue": 1,"newValue": 2,"changedAt":"2017-10-20T01:58:09.298Z","changedBy":20116}; line: 1, column: 124] (through reference chain: com.company.ChangeEvent["changedAt"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.time.Instant: no String-argument constructor/factory method to deserialize from String value ('2017-10-20T01:58:09.298Z')
at [Source: {"oldValue": 1,"newValue": 2,"changedAt":"2017-10-20T01:58:09.298Z","changedBy":20116}; line: 1, column: 124] (through reference chain: com.company.ChangeEvent["changedAt"])
at org.springframework.cloud.aws.messaging.listener.QueueMessageHandler.processHandlerMethodException(QueueMessageHandler.java:195) ~[spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:506) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:451) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:389) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.executeMessage(SimpleMessageListenerContainer.java:181) ~[spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.run(SimpleMessageListenerContainer.java:314) ~[spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$SignalExecutingRunnable.run(SimpleMessageListenerContainer.java:368) [spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Can not construct instance of java.time.Instant: no String-argument constructor/factory method to deserialize from String value ('2017-10-20T01:58:09.298Z')
at [Source: {"oldValue": 1,"newValue": 2,"changedAt":"2017-10-20T01:58:09.298Z","changedBy":20116}; line: 1, column: 124] (through reference chain: com.company.ChangeEvent["changedAt"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.time.Instant: no String-argument constructor/factory method to deserialize from String value ('2017-10-20T01:58:09.298Z')
at [Source: {"oldValue": 1,"newValue": 2,"changedAt":"2017-10-20T01:58:09.298Z","changedBy":20116}; line: 1, column: 124] (through reference chain: com.company.ChangeEvent["changedAt"])
at org.springframework.messaging.converter.MappingJackson2MessageConverter.convertFromInternal(MappingJackson2MessageConverter.java:223) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.converter.AbstractMessageConverter.fromMessage(AbstractMessageConverter.java:175) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.converter.AbstractMessageConverter.fromMessage(AbstractMessageConverter.java:167) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.converter.CompositeMessageConverter.fromMessage(CompositeMessageConverter.java:55) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverter.fromMessage(NotificationRequestConverter.java:80) ~[spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at org.springframework.cloud.aws.messaging.support.NotificationMessageArgumentResolver.resolveArgument(NotificationMessageArgumentResolver.java:45) ~[spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:98) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:138) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:107) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:490) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 8 common frames omitted
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.time.Instant: no String-argument constructor/factory method to deserialize from String value ('2017-10-20T01:58:09.298Z')
at [Source: {"oldValue": 1,"newValue": 2,"changedAt":"2017-10-20T01:58:09.298Z","changedBy":20116}; line: 1, column: 124] (through reference chain: com.company.ChangeEvent["changedAt"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1456) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1012) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:370) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:315) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1282) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:159) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:150) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:499) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:511) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:396) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1198) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:314) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:148) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:499) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:101) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:357) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:148) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3798) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2880) ~[jackson-databind-2.8.5.jar:2.8.5]
at org.springframework.messaging.converter.MappingJackson2MessageConverter.convertFromInternal(MappingJackson2MessageConverter.java:218) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 17 common frames omitted
其他信息:
我第一次尝试修复它(失败)
在我第一次尝试修复此问题时,我尝试公开 QueueMessageHandlerFactory
类型的 bean 并使用我自己的 ObjectMapper 配置它。不幸的是,这也不起作用。此故障的详细信息如下。我不确定它们是否有助于调试。
这是我暴露的bean:
@Configuration
public class AwsSqsConfig {
@Bean
public QueueMessageHandlerFactory queueMessageHandlerFactory(AmazonSQS amazonSQS,
BeanFactory beanFactory) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
mappingJackson2MessageConverter.setSerializedPayloadClass(String.class);
mappingJackson2MessageConverter.setObjectMapper(objectMapper);
Assert.notNull(amazonSQS);
Assert.notNull(beanFactory);
QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory();
factory.setAmazonSqs(amazonSQS);
factory.setBeanFactory(beanFactory);
factory.setArgumentResolvers(Arrays.asList(new PayloadArgumentResolver(mappingJackson2MessageConverter)));
return factory;
}
}
我将监听器方法和 ChangeEvent 类保留为相同,但这次出现了不同的错误:
org.springframework.messaging.MessagingException: An exception occurred while invoking the handler method; nested exception is org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Unrecognized field "Type" (class com.company.ChangeEvent), not marked as ignorable
at [Source: {
"Type" : "Notification",
"MessageId" : "e9e26416-ae16-5c60-b3a3-36752ebc3512",
"TopicArn" : "arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev",
"Message" : "{\"oldValue\":1,\"newValue\":2,\"changedAt\":\"2017-10-20T04:41:15.024Z\",\"changedBy\":20116}",
"Timestamp" : "2017-10-20T04:41:14.667Z",
"SignatureVersion" : "1",
"Signature" : "XXD+IAuCr6TUzkG1RIrreqf6OjAdvy7Bi/xZTBWOJI/LsTz5HG4QdTiTD4pZYI6jgupEhsG8BWYR8krKrwdSjfpYLD2z8pxBl4hEjgmgcCOHatKR7Hk9Sydsecr4yagrs0LUSjItB3EGv5O5Qfilps//swNaQnC+1VuIVedmaHxQi8McWBBzdBjFVs5WBHzItbRhC1KIsbf08Fnhc/XK9iAJTjY+09wUzVRs8x60NpaPoTQOYPJ1Yl7UNk4s8TQFd/pnWvRZpxv3hlh+Cz6CqwluER65lHol1tzCgAM60NcbxM+wqXE4IxfYHVG2PRKnE05x4mdjBqyVodOOXJYhtQ==",
"SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-433026a4050d206028891664da859041.pem",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev:135541fc-37de-40b3-84bc-d54cee36a10f",
"MessageAttributes" : {
"id" : {"Type":"String","Value":"1d18420f-bfcc-81b5-be6e-b7be543d5247"},
"contentType" : {"Type":"String","Value":"application/json;charset=UTF-8"},
"timestamp" : {"Type":"Number.java.lang.Long","Value":"1508474475049"}
}
}; line: 2, column: 13] (through reference chain: com.company.ChangeEvent["Type"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Type" (class com.company.ChangeEvent), not marked as ignorable)
at [Source: {
"Type" : "Notification",
"MessageId" : "e9e26416-ae16-5c60-b3a3-36752ebc3512",
"TopicArn" : "arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev",
"Message" : "{\"oldValue\":1,\"newValue\":2,\"changedAt\":\"2017-10-20T04:41:15.024Z\",\"changedBy\":20116}",
"Timestamp" : "2017-10-20T04:41:14.667Z",
"SignatureVersion" : "1",
"Signature" : "XXD+IAuCr6TUzkG1RIrreqf6OjAdvy7Bi/xZTBWOJI/LsTz5HG4QdTiTD4pZYI6jgupEhsG8BWYR8krKrwdSjfpYLD2z8pxBl4hEjgmgcCOHatKR7Hk9Sydsecr4yagrs0LUSjItB3EGv5O5Qfilps//swNaQnC+1VuIVedmaHxQi8McWBBzdBjFVs5WBHzItbRhC1KIsbf08Fnhc/XK9iAJTjY+09wUzVRs8x60NpaPoTQOYPJ1Yl7UNk4s8TQFd/pnWvRZpxv3hlh+Cz6CqwluER65lHol1tzCgAM60NcbxM+wqXE4IxfYHVG2PRKnE05x4mdjBqyVodOOXJYhtQ==",
"SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-433026a4050d206028891664da859041.pem",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev:135541fc-37de-40b3-84bc-d54cee36a10f",
"MessageAttributes" : {
"id" : {"Type":"String","Value":"1d18420f-bfcc-81b5-be6e-b7be543d5247"},
"contentType" : {"Type":"String","Value":"application/json;charset=UTF-8"},
"timestamp" : {"Type":"Number.java.lang.Long","Value":"1508474475049"}
}
}; line: 2, column: 13] (through reference chain: com.company.ChangeEvent["Type"])
at org.springframework.cloud.aws.messaging.listener.QueueMessageHandler.processHandlerMethodException(QueueMessageHandler.java:195) ~[spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:506) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:451) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:389) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.executeMessage(SimpleMessageListenerContainer.java:181) ~[spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.run(SimpleMessageListenerContainer.java:314) ~[spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$SignalExecutingRunnable.run(SimpleMessageListenerContainer.java:368) [spring-cloud-aws-messaging-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Unrecognized field "Type" (class com.company.ChangeEvent), not marked as ignorable
at [Source: {
"Type" : "Notification",
"MessageId" : "e9e26416-ae16-5c60-b3a3-36752ebc3512",
"TopicArn" : "arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev",
"Message" : "{\"oldValue\":1,\"newValue\":2,\"changedAt\":\"2017-10-20T04:41:15.024Z\",\"changedBy\":20116}",
"Timestamp" : "2017-10-20T04:41:14.667Z",
"SignatureVersion" : "1",
"Signature" : "XXD+IAuCr6TUzkG1RIrreqf6OjAdvy7Bi/xZTBWOJI/LsTz5HG4QdTiTD4pZYI6jgupEhsG8BWYR8krKrwdSjfpYLD2z8pxBl4hEjgmgcCOHatKR7Hk9Sydsecr4yagrs0LUSjItB3EGv5O5Qfilps//swNaQnC+1VuIVedmaHxQi8McWBBzdBjFVs5WBHzItbRhC1KIsbf08Fnhc/XK9iAJTjY+09wUzVRs8x60NpaPoTQOYPJ1Yl7UNk4s8TQFd/pnWvRZpxv3hlh+Cz6CqwluER65lHol1tzCgAM60NcbxM+wqXE4IxfYHVG2PRKnE05x4mdjBqyVodOOXJYhtQ==",
"SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-433026a4050d206028891664da859041.pem",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev:135541fc-37de-40b3-84bc-d54cee36a10f",
"MessageAttributes" : {
"id" : {"Type":"String","Value":"1d18420f-bfcc-81b5-be6e-b7be543d5247"},
"contentType" : {"Type":"String","Value":"application/json;charset=UTF-8"},
"timestamp" : {"Type":"Number.java.lang.Long","Value":"1508474475049"}
}
}; line: 2, column: 13] (through reference chain: com.company.ChangeEvent["Type"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Type" (class com.company.ChangeEvent), not marked as ignorable
at [Source: {
"Type" : "Notification",
"MessageId" : "e9e26416-ae16-5c60-b3a3-36752ebc3512",
"TopicArn" : "arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev",
"Message" : "{\"oldValue\":1,\"newValue\":2,\"changedAt\":\"2017-10-20T04:41:15.024Z\",\"changedBy\":20116}",
"Timestamp" : "2017-10-20T04:41:14.667Z",
"SignatureVersion" : "1",
"Signature" : "XXD+IAuCr6TUzkG1RIrreqf6OjAdvy7Bi/xZTBWOJI/LsTz5HG4QdTiTD4pZYI6jgupEhsG8BWYR8krKrwdSjfpYLD2z8pxBl4hEjgmgcCOHatKR7Hk9Sydsecr4yagrs0LUSjItB3EGv5O5Qfilps//swNaQnC+1VuIVedmaHxQi8McWBBzdBjFVs5WBHzItbRhC1KIsbf08Fnhc/XK9iAJTjY+09wUzVRs8x60NpaPoTQOYPJ1Yl7UNk4s8TQFd/pnWvRZpxv3hlh+Cz6CqwluER65lHol1tzCgAM60NcbxM+wqXE4IxfYHVG2PRKnE05x4mdjBqyVodOOXJYhtQ==",
"SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-433026a4050d206028891664da859041.pem",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev:135541fc-37de-40b3-84bc-d54cee36a10f",
"MessageAttributes" : {
"id" : {"Type":"String","Value":"1d18420f-bfcc-81b5-be6e-b7be543d5247"},
"contentType" : {"Type":"String","Value":"application/json;charset=UTF-8"},
"timestamp" : {"Type":"Number.java.lang.Long","Value":"1508474475049"}
}
}; line: 2, column: 13] (through reference chain: com.company.ChangeEvent["Type"])
at org.springframework.messaging.converter.MappingJackson2MessageConverter.convertFromInternal(MappingJackson2MessageConverter.java:223) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.converter.AbstractMessageConverter.fromMessage(AbstractMessageConverter.java:175) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.resolveArgument(PayloadArgumentResolver.java:115) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:98) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:138) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:107) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:490) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 8 common frames omitted
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Type" (class com.company.ChangeEvent), not marked as ignorable
at [Source: {
"Type" : "Notification",
"MessageId" : "e9e26416-ae16-5c60-b3a3-36752ebc3512",
"TopicArn" : "arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev",
"Message" : "{\"oldValue\":1,\"newValue\":2,\"changedAt\":\"2017-10-20T04:41:15.024Z\",\"changedBy\":20116}",
"Timestamp" : "2017-10-20T04:41:14.667Z",
"SignatureVersion" : "1",
"Signature" : "XXD+IAuCr6TUzkG1RIrreqf6OjAdvy7Bi/xZTBWOJI/LsTz5HG4QdTiTD4pZYI6jgupEhsG8BWYR8krKrwdSjfpYLD2z8pxBl4hEjgmgcCOHatKR7Hk9Sydsecr4yagrs0LUSjItB3EGv5O5Qfilps//swNaQnC+1VuIVedmaHxQi8McWBBzdBjFVs5WBHzItbRhC1KIsbf08Fnhc/XK9iAJTjY+09wUzVRs8x60NpaPoTQOYPJ1Yl7UNk4s8TQFd/pnWvRZpxv3hlh+Cz6CqwluER65lHol1tzCgAM60NcbxM+wqXE4IxfYHVG2PRKnE05x4mdjBqyVodOOXJYhtQ==",
"SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-433026a4050d206028891664da859041.pem",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:799735207477:matchStatusUpdated-dev:135541fc-37de-40b3-84bc-d54cee36a10f",
"MessageAttributes" : {
"id" : {"Type":"String","Value":"1d18420f-bfcc-81b5-be6e-b7be543d5247"},
"contentType" : {"Type":"String","Value":"application/json;charset=UTF-8"},
"timestamp" : {"Type":"Number.java.lang.Long","Value":"1508474475049"}
}
}; line: 2, column: 13] (through reference chain: com.company.ChangeEvent["Type"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:834) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1093) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1477) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1455) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:282) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3798) ~[jackson-databind-2.8.5.jar:2.8.5]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2880) ~[jackson-databind-2.8.5.jar:2.8.5]
at org.springframework.messaging.converter.MappingJackson2MessageConverter.convertFromInternal(MappingJackson2MessageConverter.java:218) ~[spring-messaging-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 14 common frames omitted
基本上,所有这些堆栈跟踪都意味着我错误配置了 QueueMessageHandler,导致无法反序列化 NotificationMessage。
摘要
就像我之前说过的,我需要知道如何修改 Spring Cloud AWS 用于反序列化 SQS 消息的对象映射器。有谁知道该怎么做吗?
谢谢!
最佳答案
您正在尝试监听 SQS 队列上的 SNS 消息。因为它们基本上是 SNS 消息,所以负载被包装在通知消息中(这就是为什么在 SQSListener 上设置了 @NotificationMessage 注释)。
这实际上是让监听器使用NotificationMessageArgumentResolver而不是PayloadArgumentResolver来解析消息。 NotificationMessageArgumentResolver 需要一个NotificationRequestConverter 来完成这项工作。
请尝试这个配置,我自己在SNS上测试过-->SQS消息成功:
@Configuration
public class AwsSqsConfig {
@Bean
public QueueMessageHandlerFactory queueMessageHandlerFactory(
AmazonSQSAsync amazonSQS, BeanFactory beanFactory) {
ObjectMapper objectMapper = new ObjectMapper();
// This is the java time module needed in the mapper (can be read in the question)
objectMapper.registerModule(new JavaTimeModule());
// Wrapped in this
MappingJackson2MessageConverter jacksonMessageConverter =
new MappingJackson2MessageConverter();
jacksonMessageConverter.setSerializedPayloadClass(String.class);
jacksonMessageConverter.setObjectMapper(objectMapper);
jacksonMessageConverter.setStrictContentTypeMatch(true);
// Wrapped in this
List<MessageConverter> payloadArgumentConverters = new ArrayList<>();
payloadArgumentConverters.add(jacksonMessageConverter);
// This is the converter that is invoked on SNS messages on SQS listener
NotificationRequestConverter notificationRequestConverter =
new NotificationRequestConverter(jacksonMessageConverter);
payloadArgumentConverters.add(notificationRequestConverter);
payloadArgumentConverters.add(new SimpleMessageConverter());
// It needs to be wrapped in this
CompositeMessageConverter compositeMessageConverter =
new CompositeMessageConverter(payloadArgumentConverters);
Assert.notNull(amazonSQS);
Assert.notNull(beanFactory);
QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory();
factory.setAmazonSqs(amazonSQS);
factory.setBeanFactory(beanFactory);
// The factory has this method for custom resolvers (can be read in the question)
factory.setArgumentResolvers(Arrays.asList(
new NotificationMessageArgumentResolver(compositeMessageConverter)));
return factory;
}
}
您的尝试是正确的,它实际上对上述解决方案有很大帮助,谢谢。如果您的解决方案是一条简单的 SQS 消息,而不是 SQS 上的 SNS,那么您的解决方案绝对有效(也尝试过)。
关于spring - 如何修改 Spring Cloud AWS 用于反序列化 SQS 消息的对象映射器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46842633/
我在 lambda 中有以下代码: entries = [ { "Id": str(index), "MessageAttribut
我正在构建一个无服务器应用程序,它在资源中定义了一个 SQS 队列,如下所示: resources: Resources: TheQueue: Type: "AWS:SQS:Q
我正在使用无服务器框架来使用来自 SQS 的消息。一些发送到队列的消息不会被消费。他们直接进入飞行中的 SQS 状态,然后从那里进入我的死信队列。当我查看我的消费者日志时,我可以看到它消费并成功处理了
我们的亚马逊 SQS 队列没有收到来自亚马逊 MWS 的 AnyOfferChanged 通知消息。 我们发送一个测试通知,当我们收到通知时,它会被发送到队列并可用。 我们已经设置了两个 AWS 账户
我想知道最后一条消息何时发布到 SQS 队列。 查看队列属性(通过 CLI 或其他方式),我看不到任何合适的内容 - 只能看到队列属性最后一次修改的时间。 如果有什么技巧可以找到这个(在不了解客户的情
我正在使用无服务器框架来使用来自 SQS 的消息。一些发送到队列的消息不会被消费。他们直接进入飞行中的 SQS 状态,然后从那里进入我的死信队列。当我查看我的消费者日志时,我可以看到它消费并成功处理了
我们的亚马逊 SQS 队列没有收到来自亚马逊 MWS 的 AnyOfferChanged 通知消息。 我们发送一个测试通知,当我们收到通知时,它会被发送到队列并可用。 我们已经设置了两个 AWS 账户
我正在使用 Amazon SQS 队列向外部系统发送通知。 如果使用 SQS 时 HTTP 请求失败 SendMessage ,我不知道消息是否已排队。我的默认策略是重试将消息发布到队列,但存在两次发
来自 SNS FAQ ,我知道 SNS 到 SQS 有重试策略,但是他们是否保证至少向 SQS 传递一条消息? 请给官方报价。 最佳答案 见 https://aws.amazon.com/sqs/fa
我是否可以使用 Amazon PHP SDK 根据消息 ID 从 SQS 队列中获取消息?我是否必须获取队列中的所有消息,然后在我的服务器上对其进行过滤? 我的服务器收到一个带有队列消息 ID 的 S
我意外删除了 Amazon SQS 中的队列。有没有办法检索/撤消删除? 最佳答案 不,队列(以及队列上的任何消息)将永远消失。 如果您使用相同名称重新创建队列,它将保留相同的 ARN 和 URL。希
我的大多数 Celery 任务的 ETA 都长于 Amazon SQS 定义的最大可见性超时。 celery documentation说: This causes problems with ETA
我正在实现 SQS fifo 队列。我必须使用 cloudformation 模板来实现。 当我放大推送时,我得到 错误API:sqs:CreateQueue 对资源 https://sqs.us-e
我有一个代码,我需要将消息发送到现有的 sqs 队列。 我在 aws-cdk 中有这段代码。但这是行不通的。没有添加访问权限。 const sqsQ = sqs.Queue.fromQueueArn(
我很想了解 GCP 的 PubSub 的实现。尽管 Pubsub 似乎指向遵循发布-订阅设计模式,但它似乎比 AWS SNS(使用发布-订阅模型)更接近 AWS 的 SQS(队列)。为什么认为这是,G
序言:我正在尝试为我认为是一个非常常见的用例提出一个建议,我想使用 Amazon 的 SWF 和 SQS 来实现我的目标。可能还有其他服务可以更好地匹配我正在尝试做的事情,因此,如果您有任何建议,请随
AWS SQS 是否可以通过某种方式调用我的 REST API?基本上,一旦消息被推送到 AWS SQS,我就想听到它并执行所需的操作。我可以安排一个每秒可以提取消息的监听器,但这不是一个优化解决方案
我已配置 SQS 监听器来使用消息列表中的消息,但一次只收到一条消息,并收到错误,因为无法将 model.StudentData 转换为 java.util.ArrayList 的实例 我的代码是:-
使用 Amazon Simple Queue Service 发送消息需要多长时间? 另外,我想知道在 Amazon SQS 中一分钟内会发送多少条消息? 最佳答案 截至 2007 年,at leas
我正在使用 Amazon-SQS,我尝试从队列中检索大约数量的属性,但响应为空 我正在使用 C# 以下是代码: GetQueueAttributesRequest attReq = new GetQu
我是一名优秀的程序员,十分优秀!