@Test public void testGetMessageType() throws Exception { DefaultRocketMQListenerContainer listenerContainer = new DefaultRocketMQListenerContainer(); Method getMessageType = DefaultRocketMQListenerContainer.class.getDeclaredMethod("getMessageType"); getMessageType.setAccessible(true); listenerContainer.setRocketMQListener(new RocketMQListener<String>() { @Override public void onMessage(String message) { } }); Class result = (Class)getMessageType.invoke(listenerContainer); assertThat(result.getName().equals(String.class.getName())); listenerContainer.setRocketMQListener(new RocketMQListener<MessageExt>() { @Override public void onMessage(MessageExt message) { } }); result = (Class)getMessageType.invoke(listenerContainer); assertThat(result.getName().equals(MessageExt.class.getName())); }
private Class getMessageType() { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); Type[] interfaces = targetClass.getGenericInterfaces(); Class<?> superclass = targetClass.getSuperclass(); while ((Objects.isNull(interfaces) || 0 == interfaces.length) && Objects.nonNull(superclass)) { interfaces = superclass.getGenericInterfaces(); superclass = targetClass.getSuperclass(); } if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if (Objects.equals(parameterizedType.getRawType(), RocketMQListener.class)) { Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return (Class) actualTypeArguments[0]; } else { return Object.class; } } } } return Object.class; } else { return Object.class; } }
DefaultRocketMQListenerContainer implements InitializingBean,
    RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private Class getMessageType() { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); Type[] interfaces = targetClass.getGenericInterfaces(); Class<?> superclass = targetClass.getSuperclass(); while ((Objects.isNull(interfaces) || 0 == interfaces.length) && Objects.nonNull(superclass)) { interfaces = superclass.getGenericInterfaces(); superclass = targetClass.getSuperclass(); } if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if (Objects.equals(parameterizedType.getRawType(), RocketMQListener.class)) { Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return (Class) actualTypeArguments[0]; } else { return Object.class; } } } } return Object.class; } else { return Object.class; } } }
DefaultRocketMQListenerContainer implements InitializingBean,
    RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private Class getMessageType() { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); Type[] interfaces = targetClass.getGenericInterfaces(); Class<?> superclass = targetClass.getSuperclass(); while ((Objects.isNull(interfaces) || 0 == interfaces.length) && Objects.nonNull(superclass)) { interfaces = superclass.getGenericInterfaces(); superclass = targetClass.getSuperclass(); } if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if (Objects.equals(parameterizedType.getRawType(), RocketMQListener.class)) { Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return (Class) actualTypeArguments[0]; } else { return Object.class; } } } } return Object.class; } else { return Object.class; } }  }
DefaultRocketMQListenerContainer implements InitializingBean,
    RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private Class getMessageType() { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); Type[] interfaces = targetClass.getGenericInterfaces(); Class<?> superclass = targetClass.getSuperclass(); while ((Objects.isNull(interfaces) || 0 == interfaces.length) && Objects.nonNull(superclass)) { interfaces = superclass.getGenericInterfaces(); superclass = targetClass.getSuperclass(); } if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if (Objects.equals(parameterizedType.getRawType(), RocketMQListener.class)) { Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return (Class) actualTypeArguments[0]; } else { return Object.class; } } } } return Object.class; } else { return Object.class; } }  long getSuspendCurrentQueueTimeMillis(); void setSuspendCurrentQueueTimeMillis(long suspendCurrentQueueTimeMillis); int getDelayLevelWhenNextConsume(); void setDelayLevelWhenNextConsume(int delayLevelWhenNextConsume); String getNameServer(); void setNameServer(String nameServer); String getConsumerGroup(); void setConsumerGroup(String consumerGroup); String getTopic(); void setTopic(String topic); int getConsumeThreadMax(); String getCharset(); void setCharset(String charset); ObjectMapper getObjectMapper(); void setObjectMapper(ObjectMapper objectMapper); RocketMQListener getRocketMQListener(); void setRocketMQListener(RocketMQListener rocketMQListener); RocketMQMessageListener getRocketMQMessageListener(); void setRocketMQMessageListener(RocketMQMessageListener anno); ConsumeMode getConsumeMode(); SelectorType getSelectorType(); String getSelectorExpression(); MessageModel getMessageModel(); DefaultMQPushConsumer getConsumer(); void setConsumer(DefaultMQPushConsumer consumer); @Override void setupMessageListener(RocketMQListener rocketMQListener); @Override void destroy(); @Override boolean isAutoStartup(); @Override void stop(Runnable callback); @Override void start(); @Override void stop(); @Override boolean isRunning(); @Override int getPhase(); @Override void afterPropertiesSet(); @Override void setApplicationContext(ApplicationContext applicationContext); @Override String toString(); }
DefaultRocketMQListenerContainer implements InitializingBean,
    RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private Class getMessageType() { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); Type[] interfaces = targetClass.getGenericInterfaces(); Class<?> superclass = targetClass.getSuperclass(); while ((Objects.isNull(interfaces) || 0 == interfaces.length) && Objects.nonNull(superclass)) { interfaces = superclass.getGenericInterfaces(); superclass = targetClass.getSuperclass(); } if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if (Objects.equals(parameterizedType.getRawType(), RocketMQListener.class)) { Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return (Class) actualTypeArguments[0]; } else { return Object.class; } } } } return Object.class; } else { return Object.class; } }  long getSuspendCurrentQueueTimeMillis(); void setSuspendCurrentQueueTimeMillis(long suspendCurrentQueueTimeMillis); int getDelayLevelWhenNextConsume(); void setDelayLevelWhenNextConsume(int delayLevelWhenNextConsume); String getNameServer(); void setNameServer(String nameServer); String getConsumerGroup(); void setConsumerGroup(String consumerGroup); String getTopic(); void setTopic(String topic); int getConsumeThreadMax(); String getCharset(); void setCharset(String charset); ObjectMapper getObjectMapper(); void setObjectMapper(ObjectMapper objectMapper); RocketMQListener getRocketMQListener(); void setRocketMQListener(RocketMQListener rocketMQListener); RocketMQMessageListener getRocketMQMessageListener(); void setRocketMQMessageListener(RocketMQMessageListener anno); ConsumeMode getConsumeMode(); SelectorType getSelectorType(); String getSelectorExpression(); MessageModel getMessageModel(); DefaultMQPushConsumer getConsumer(); void setConsumer(DefaultMQPushConsumer consumer); @Override void setupMessageListener(RocketMQListener rocketMQListener); @Override void destroy(); @Override boolean isAutoStartup(); @Override void stop(Runnable callback); @Override void start(); @Override void stop(); @Override boolean isRunning(); @Override int getPhase(); @Override void afterPropertiesSet(); @Override void setApplicationContext(ApplicationContext applicationContext); @Override String toString();  }