异常异常与SpringAMQPMessageSource.onMessage(Message,Channel)Axon中的throws子句不兼容

时间:2018-11-04 11:52:50

标签: java spring-boot axon

我正在Spring Boot + Axon Framework开发示例中进行解释,https://www.youtube.com/watch?v=Jp-rW-XOYzA&list=PLgGXSWYM2FpOa_FTla-x5Wd10dpmgrRC4&index=54。在此示例中,我仅使用最新的依赖项,而其他内容则保持不变。

当我简单地运行代码时,出现以下错误,并且在此行中已经出现了问题。请引导我。

错误:-

java.lang.Error: Unresolved compilation problem: 
    Exception Exception is not compatible with throws clause in SpringAMQPMessageSource.onMessage(Message, Channel)

    at com.example.DemoComplaintsStatsApplication$1.onMessage(DemoComplaintsStatsApplication.java:54) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]
    at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:181) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:114) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:51) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:188) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:126) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1414) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1337) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1324) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1303) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:817) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:801) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:77) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1042) ~[spring-rabbit-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_151]

DemoComplaintsStatsApplication.java

@SpringBootApplication
public class DemoComplaintsStatsApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoComplaintsStatsApplication.class, args);
    }


    @ProcessingGroup("amqpEvents")
    @RestController
    public static class ComplaintStatisticsAPI {

        private ConcurrentMap<String, AtomicLong> staticstics = new ConcurrentHashMap<>();

        @EventHandler
        public void on(ComplaintFileEvent event) {
            staticstics.computeIfAbsent(event.getCompany(), k -> new AtomicLong()).incrementAndGet();
        }

        @GetMapping
        public Map<String, AtomicLong> getStatistics(){
            return staticstics;
        }
    }

    @Bean
    public SpringAMQPMessageSource complaintEvents(Serializer serializer) {
        return new SpringAMQPMessageSource(new DefaultAMQPMessageConverter(serializer)) {

            @RabbitListener(queues = "ComplaintEvents")
            @Override
            public void onMessage(Message message, Channel channel) throws Exception {
                super.onMessage(message, channel);
            }
        };
    }
}

enter image description here

1 个答案:

答案 0 :(得分:1)

SpringAMQPMessageSource#onMessage(Message, Channel)函数曾经是SpringAMQPMessageSource#onMessage(Message, Channel) throws Exception。但是从3.4版开始,情况就不再如此。

我看到您也在Axon Framework上发布了另一个StackOverflow,您是否已升级到3.4版,对吗? 我想指出3.4 不是该框架的最新版本,因为它是4.0。 4.0还包括对Axon Server的非常简单的介绍,https://imgur.com/a/DPd8eoD是一种免费的替代品,可用于存储应用程序之间的事件和发布消息(例如命令,事件和查询)。很快,它完全不需要'Spring AMQP'软件包,应该会大大简化您的代码。

不过,要解决您的问题,请删除覆盖的throws Exception函数上的onMessage(Message, Channel)应该可以解决问题。