使用Spring Cloud Bus的Spring Cloud Config

时间:2019-04-06 15:07:59

标签: spring-boot rabbitmq spring-amqp spring-cloud-config spring-cloud-bus

我正在尝试将Spring Cloud Bus与我的配置服务器集成在一起,以刷新我们服务的配置。对于所有服务,它的工作正常。但是在一项已经配置了侦听器的服务中,它为RefreshRemoteApplicationEvent和AckRemoteApplicationEvent提供了以下异常。我不确定是否需要为此类型编写自定义映射器。请帮助/建议我。

Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'AckRemoteApplicationEvent' into a subtype of [simple type, class org.springframework.cloud.bus.event.RemoteApplicationEvent]: known type ids = [RemoteApplicationEvent] at [Source:{"type":"AckRemoteApplicationEvent","timestamp":1554561718361,"originService":"cm-config:local:8888","destinationService":"**","id":"743ecc3c-228e-4046-a4f9-e169740b6cff","ackId":"ac66387d-fa22-40d5-985d-29d91ff227fc","ackDestinationService":"**","event":"org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent"}; line: 1, column: 9]

Caused by: org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Could not resolve type id 'RefreshRemoteApplicationEvent' into a subtype of [simple type, class org.springframework.cloud.bus.event.RemoteApplicationEvent]: known type ids = [RemoteApplicationEvent] at [Source:{"type":"RefreshRemoteApplicationEvent","timestamp":1554561718297,"originService":"cm-config:local:8888","destinationService":"**","id":"ac66387d-fa22-40d5-985d-29d91ff227fc"}; line: 1, column: 9]; nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'RefreshRemoteApplicationEvent' into a subtype of [simple type, class org.springframework.cloud.bus.event.RemoteApplicationEvent]: known type ids= [RemoteApplicationEvent] at [Source: {"type":"RefreshRemoteApplicationEvent","timestamp":1554561718297,"originService":"cm-config:local:8888","destinationService":"**","id":"ac66387d-fa22-40d5-985d-29d91ff227fc"}; line: 1,column: 9]

如果需要更多详细信息,请告知我。

服务中现有的RabbitMQ配置给我带来了问题。如果我做错了事,请告诉我。

@Bean
Binding binding(Queue queue, TopicExchange exchange) {
    return BindingBuilder.bind(queue).to(exchange).with(routingKey);
}

@Bean
public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) {
    final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
    rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());
    return rabbitTemplate;
}

@Bean
public Jackson2JsonMessageConverter producerJackson2MessageConverter() {
    return new Jackson2JsonMessageConverter();
}

@Bean
public MappingJackson2MessageConverter consumerJackson2MessageConverter() {
    return new MappingJackson2MessageConverter();
}

@Bean
public DefaultMessageHandlerMethodFactory messageHandlerMethodFactory() {
    DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
    factory.setMessageConverter(consumerJackson2MessageConverter());
    return factory;
}

@Override
public void configureRabbitListeners(final RabbitListenerEndpointRegistrar registrar) {
    registrar.setMessageHandlerMethodFactory(messageHandlerMethodFactory());
}

谢谢, 萨加尔

0 个答案:

没有答案