1

I have classes:

public class MqMessage implements Serializable{
    private String event;
    private String absolutePath;
    private boolean isDirectory;
    private Integer hash;
    private Node node;

    get/set

}

Configuration class: public class RabbitConfiguration {

@Bean
public ConnectionFactory connectionFactory() {
    CachingConnectionFactory connectionFactory =
            new CachingConnectionFactory("localhost");
    return connectionFactory;
}

@Bean
public AmqpAdmin amqpAdmin() {
    return new RabbitAdmin(connectionFactory());
}

@Bean
public RabbitTemplate rabbitTemplate() {
    RabbitTemplate template = new RabbitTemplate(connectionFactory());
    template.setExchange("exchange-events");
    return template;
}

//объявляем очередь
@Bean
public Queue myQueue1() {
    return new Queue("queue-events");
}

@Bean
public FanoutExchange fanoutExchangeA() {
    return new FanoutExchange("exchange-events");
}

@Bean
public Binding binding1() {
    return BindingBuilder.bind(myQueue1()).to(fanoutExchangeA());
}

Send message

    public class ServerHandler implements EventHandler {

        //сама структура отражающая состояние файлов, содеражащая метоы для работы с ними
        @Autowired
        Node fileTreeRoot;

        SimpleMessageConverter simpleMessageConverter;

        @Override
        public void setRoot(Node fileTreeRoot) {
            this.fileTreeRoot = fileTreeRoot;
        }
        @Autowired
        RabbitTemplate rabbitTemplate;

        //логика обработки событий
        @Override
        public void eventHandle(String event, String path) {

            /*bussines-logick
*/
            rabbitTemplate.setExchange("exchange-events");

            rabbitTemplate.convertAndSend(new MqMessage(event,fileTreeRoot));
            return;
        }

        public ServerHandler() {

    }

Listener:

public class Client {
Node rootNodeClient = new Node();
EventHandler handlerClient = new ClientHandler();


@RabbitListener(queues = "queue-events")
public void onMessage(MqMessage message) {
    System.out.println(message.getNode().hashCode());
    rootNodeClient = message.getNode();
}

a have error only start app

2017-08-08 12:58:02.128 WARN 5024 --- [cTaskExecutor-1] s.a.r.l.ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed.

org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener method could not be invoked with the incoming message

Caused by: org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException: Could not resolve method parameter at index 0 in public void prcjt.client.Client.onMessage(prcjt.message.MqMessage): 1 error(s): [Error in object 'message': codes []; arguments []; default message [Payload value must not be empty]]

Error does not always exist Help please

Mr.Ki.D.
  • 111
  • 1
  • 1
  • 3

3 Answers3

3

Using mappingJackson2MessageConverted did not work for me. After lots of investigation found that I was using wrong converter. Add the below code in Listener service, it worked for me.

@Bean
public Jackson2JsonMessageConverter converter() {
    return new Jackson2JsonMessageConverter();
}
1
Caused by: org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException: Could not resolve method parameter at index 0

From the exception information, it seems that spring could not resolve MqMessage in the listener correctly, you can try to add a mappingJackson2MessageConverter to the client. Refer to this link.

Dave Pateral
  • 1,415
  • 1
  • 14
  • 21
  • 1
    I think the story is exactly opposite- `Payload value must not be empty`. That means the converted is configured for the listener container can't properly deserialize the body. Looks like the `RabbitTemplate` uses the default `SimpleMessageConverter` and serialize `MqMessage` using standard JAva serialization, but container factory is based on some other converter, maybe even that mentioned `mappingJackson2MessageConverter`. You definitely should use the same converter on the consumer side – Artem Bilan Aug 08 '17 at 11:36
1

I faced this issue for couple of reasons:

  1. Not using "implements Serializable" (which I see you are already using)

  2. No constructor in model class. (Use empty constructor)

    public ClassToGetQData() {
        super();
        // TODO Auto-generated constructor stub
    }
    

Also, using @JsonIgnoreProperties(ignoreUnknown = true) helped me with missing data elements in incoming data.

ZygD
  • 22,092
  • 39
  • 79
  • 102
Sri
  • 36
  • 2