Announcement Announcement Module
Collapse
No announcement yet.
failed to invoke target method 'handleMessage' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • failed to invoke target method 'handleMessage'

    I'm getting the following when trying to consume a message. It seems the message is a byte[] instead of the expected POJO.

    Aug 13, 2010 12:28:54 PM org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer invokeErrorHandler
    WARNING: Execution of Rabbit message listener failed, and no ErrorHandler has been set.
    org.springframework.amqp.rabbit.listener.adapter.L istenerExecutionFailedException: Failed to invoke target method 'handleMessage' with argument type = [class [B], value = [{[B@c42804}]
    at org.springframework.amqp.rabbit.listener.adapter.M essageListenerAdapter.invokeListenerMethod(Message ListenerAdapter.java:462)
    at org.springframework.amqp.rabbit.listener.adapter.M essageListenerAdapter.onMessage(MessageListenerAda pter.java:346)
    at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.doInvokeListener(AbstractM essageListenerContainer.java:288)
    at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.invokeListener(AbstractMes sageListenerContainer.java:250)
    at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.doExecuteListener(Abstract MessageListenerContainer.java:229)
    at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.executeListener(AbstractMe ssageListenerContainer.java:198)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.processMessage(SimpleMessage ListenerContainer.java:229)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer$AsyncMessageProcessingConsum er.run(SimpleMessageListenerContainer.java:288)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.NoSuchMethodException: PolyCalcHandler.handleMessage([B)
    at java.lang.Class.getMethod(Class.java:1605)
    at org.springframework.util.MethodInvoker.prepare(Met hodInvoker.java:178)
    at org.springframework.amqp.rabbit.listener.adapter.M essageListenerAdapter.invokeListenerMethod(Message ListenerAdapter.java:442)
    ... 8 more

  • #2
    Can you provide a bit more context? Specifically your MessageConverter and the content-type?

    Thanks,
    Mark

    Comment


    • #3
      Sorry for being vague. I'm using the AmqpOutputboundEndpoint sandbox code to send the message and it works fine using a JRuby consumer. Now I'm working on writing a Java consumer using Spring AMQP. Here's my configuration:

      Code:
      @Configuration
      public class ConsumerConfiguration extends AbstractRabbitConfiguration {
      
        protected static final String QUEUE_NAME = "dbcm-ply-key";
      
        @Bean
        public SimpleMessageListenerContainer listenerContainer() {
          SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
          container.setConnectionFactory(connectionFactory());    
          container.setQueueName(QUEUE_NAME);
          container.setMessageListener(new MessageListenerAdapter(new PolyCalcHandler()));
          return container;
        }
      
        @Bean
        public ConnectionFactory connectionFactory() {
          SingleConnectionFactory connectionFactory = new SingleConnectionFactory("localhost");
          connectionFactory.setUsername("guest");
          connectionFactory.setPassword("guest");
          return connectionFactory;
        }
      
        @Override
        public RabbitTemplate rabbitTemplate() {
          RabbitTemplate template = new RabbitTemplate(connectionFactory());
          template.setMessageConverter(getJsonMessageConverter());
          template.setExchange("dbcm-ex");
          template.setRoutingKey(QUEUE_NAME);
          template.setQueue(QUEUE_NAME);
          return template;
        }
      
        @Bean
        public Queue dbcmPlyQueue() {
          return new Queue(QUEUE_NAME);
        }
      
        public MessageConverter getJsonMessageConverter() {
          return new JsonMessageConverter();
        }
      }
      ----

      Here's the PolyCalcHandler:

      Code:
      public class PolyCalcHandler {
        public void handleMessage(PolyCalcRequest request) {
          System.out.println(request);
      //    return null;
        }
      }
      If I specify the above argument for handleMessage, it blows up with the exception. If I specify Object as the arg it hits the method without exception but the message arrives as a byte[]. Am I missing something from the configuration?

      Thanks
      Last edited by digitalsanctum; Aug 13th, 2010, 12:38 PM. Reason: added code tags

      Comment


      • #4
        The Message's body is a byte array, and since you have no explicit MessageConverter set on the SimpleMessageListenerContainer, it will use the default implementation: SimpleMessageConverter. That should be able to handle serialized Java objects *if* the Message has the proper content-type header value ("application/x-java-serialized-object"). If you are using the outbound endpoint from the sandbox, then it should be setting that content-type if you are passing it an Object and using the default MessageConverter on that side as well. Is that the case?

        Comment


        • #5
          Mark,

          I later figured out I was missing the JsonMessageConverter on the SimpleMessageListenerContainer. Once I added it everything seemed to work as expected.

          It seems the SimpleMessageConverter was not able to do the conversion since I was getting a byte[] instead of the expected object. I'm using the default MessageConverter is on the outbound endpoint. What's the easiest way to verify a message has the proper content-type header value?

          Thanks,
          Shane

          Comment

          Working...
          X