我尝试通过定期设置来自队列的poller to poll(JSON)消息来实现Spring IntegrationFlow以使用AWS SQS队列,然后处理消息然后保存到我的数据库。
我成功地从队列中轮询单个JSON消息模式并转换为我的自定义对象。现在我将2种类型的JSON模式发送到同一个SQS队列。例如,
`"Type" : "Notification",
"MessageId" : "xxxx-xxxx-xxxx",
"TopicArn" : "arn:aws:sns:us-west-2:xxxxx:topicName00",
"Subject" : "OK: \"test00\" in US-West-2",
"Message" : "{\"AlarmName\":\"test00\..."`
和
`"Type" : "Notification",
"MessageId" : "xxxxx-xxxx-xxxxx",
"TopicArn" : "arn:aws:sns:us-west-2:xxxxxx:topicName01",
"Message" : "{\"version\":\"0\",\"id\":\"xxxxx\",\"detail-type\":\"EC2 Instance State-change Notification\",\"source\":\"aws.ec2\..."`
这些消息被发送到同一个队列,我想使用相同的轮询器轮询队列,然后根据消息体将消息路由到不同的变换器和serviceActivator(句柄)。
@Bean
public IntegrationFlow sqsIntegrationFlow()
{
return IntegrationFlows.from( this.sqsMessageSource(), c -> c.poller( myPoller() ) )
.channel( new DirectChannel() )
.<Payload,Boolean>route( input -> input.value().contains( "EC2 Instance State-change Notification" ),
mapping -> mapping
.subFlowMapping( "true", sf -> sf.channel( new DirectChannel() )
.transform(
SqsMessageToInstanceConverter::convertSqsMessagesToInstanceInfo )
.channel( new DirectChannel() ).handle( ( message ) -> {
ec2InstanceService.updateInstanceInfo( (List<SqsMessageResult>) message.getPayload() );
} ) )
.subFlowMapping( "false", sf -> sf.channel( new DirectChannel() )
.transform( SqsMessageToInstanceConverter::convertSqsMessageToAlarmInfo )
.channel( new DirectChannel() ).handle( (alarm -> {
cwAlarmService.updateAlarmInfo(
(List<SqsAlarmMessageResult>) alarm.getPayload() );
}) ) ) )
.get();
}
我尝试使用上面的路由器并使用消息体中的字符串识别消息(&#34; EC2实例状态更改通知&#34;)但是出现错误
java.lang.ClassNotFoundException: org.springframework.integration.support.management.MappingMessageRouterManagement
我的问题是:
1。这是使用路由器的正确方法吗?
2。如何通过集成流程完成处理2个不同JSON消息的目标?
答案 0 :(得分:1)
是的,这是正确的(我在大约一个小时前写了类似的流程)。看起来你有某种类路径问题 - 该接口与路由器在同一个jar中。你在哪里运行你的应用程序?
尝试使用-verbose
JVM arg运行,我刚刚做了并得到了这个......
...
[Loaded org.springframework.integration.router.AbstractMessageRouter from file:/Users/.../.m2/repository/org/springframework/integration/spring-integration-core/4.2.5.RELEASE/spring-integration-core-4.2.5.RELEASE.jar]
[Loaded org.springframework.integration.support.management.MappingMessageRouterManagement from file:/Users/.../.m2/repository/org/springframework/integration/spring-integration-core/4.2.5.RELEASE/spring-integration-core-4.2.5.RELEASE.jar]
...