@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())); listenerContainer.setRocketMQReplyListener(new RocketMQReplyListener<MessageExt, String>() { @Override public String onMessage(MessageExt message) { return "test"; } }); result = (Class) getMessageType.invoke(listenerContainer); assertThat(result.getName().equals(MessageExt.class.getName())); listenerContainer.setRocketMQReplyListener(new RocketMQReplyListener<String, String>() { @Override public String onMessage(String message) { return "test"; } }); result = (Class) getMessageType.invoke(listenerContainer); assertThat(result.getName().equals(String.class.getName())); }
private Type getMessageType() { Class<?> targetClass; if (rocketMQListener != null) { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); } else { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQReplyListener); } Type matchedGenericInterface = null; while (Objects.nonNull(targetClass)) { Type[] interfaces = targetClass.getGenericInterfaces(); if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType && (Objects.equals(((ParameterizedType) type).getRawType(), RocketMQListener.class) || Objects.equals(((ParameterizedType) type).getRawType(), RocketMQReplyListener.class))) { matchedGenericInterface = type; break; } } } targetClass = targetClass.getSuperclass(); } if (Objects.isNull(matchedGenericInterface)) { return Object.class; } Type[] actualTypeArguments = ((ParameterizedType) matchedGenericInterface).getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return actualTypeArguments[0]; } return Object.class; }
DefaultRocketMQListenerContainer implements InitializingBean,
    RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private Type getMessageType() { Class<?> targetClass; if (rocketMQListener != null) { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); } else { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQReplyListener); } Type matchedGenericInterface = null; while (Objects.nonNull(targetClass)) { Type[] interfaces = targetClass.getGenericInterfaces(); if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType && (Objects.equals(((ParameterizedType) type).getRawType(), RocketMQListener.class) || Objects.equals(((ParameterizedType) type).getRawType(), RocketMQReplyListener.class))) { matchedGenericInterface = type; break; } } } targetClass = targetClass.getSuperclass(); } if (Objects.isNull(matchedGenericInterface)) { return Object.class; } Type[] actualTypeArguments = ((ParameterizedType) matchedGenericInterface).getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return actualTypeArguments[0]; } return Object.class; } }
DefaultRocketMQListenerContainer implements InitializingBean,
    RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private Type getMessageType() { Class<?> targetClass; if (rocketMQListener != null) { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); } else { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQReplyListener); } Type matchedGenericInterface = null; while (Objects.nonNull(targetClass)) { Type[] interfaces = targetClass.getGenericInterfaces(); if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType && (Objects.equals(((ParameterizedType) type).getRawType(), RocketMQListener.class) || Objects.equals(((ParameterizedType) type).getRawType(), RocketMQReplyListener.class))) { matchedGenericInterface = type; break; } } } targetClass = targetClass.getSuperclass(); } if (Objects.isNull(matchedGenericInterface)) { return Object.class; } Type[] actualTypeArguments = ((ParameterizedType) matchedGenericInterface).getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return actualTypeArguments[0]; } return Object.class; }  }
DefaultRocketMQListenerContainer implements InitializingBean,
    RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private Type getMessageType() { Class<?> targetClass; if (rocketMQListener != null) { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); } else { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQReplyListener); } Type matchedGenericInterface = null; while (Objects.nonNull(targetClass)) { Type[] interfaces = targetClass.getGenericInterfaces(); if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType && (Objects.equals(((ParameterizedType) type).getRawType(), RocketMQListener.class) || Objects.equals(((ParameterizedType) type).getRawType(), RocketMQReplyListener.class))) { matchedGenericInterface = type; break; } } } targetClass = targetClass.getSuperclass(); } if (Objects.isNull(matchedGenericInterface)) { return Object.class; } Type[] actualTypeArguments = ((ParameterizedType) matchedGenericInterface).getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return actualTypeArguments[0]; } return Object.class; }  long getSuspendCurrentQueueTimeMillis(); void setSuspendCurrentQueueTimeMillis(long suspendCurrentQueueTimeMillis); int getDelayLevelWhenNextConsume(); void setDelayLevelWhenNextConsume(int delayLevelWhenNextConsume); String getNameServer(); void setNameServer(String nameServer); AccessChannel getAccessChannel(); void setAccessChannel(AccessChannel accessChannel); String getConsumerGroup(); void setConsumerGroup(String consumerGroup); String getTopic(); void setTopic(String topic); int getConsumeThreadMax(); String getCharset(); void setCharset(String charset); MessageConverter getMessageConverter(); DefaultRocketMQListenerContainer setMessageConverter(MessageConverter messageConverter); RocketMQListener getRocketMQListener(); void setRocketMQListener(RocketMQListener rocketMQListener); RocketMQReplyListener getRocketMQReplyListener(); void setRocketMQReplyListener(RocketMQReplyListener rocketMQReplyListener); RocketMQMessageListener getRocketMQMessageListener(); void setRocketMQMessageListener(RocketMQMessageListener anno); ConsumeMode getConsumeMode(); SelectorType getSelectorType(); void setSelectorExpression(String selectorExpression); String getSelectorExpression(); MessageModel getMessageModel(); DefaultMQPushConsumer getConsumer(); void setConsumer(DefaultMQPushConsumer consumer); @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(); void setName(String name); }
DefaultRocketMQListenerContainer implements InitializingBean,
    RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private Type getMessageType() { Class<?> targetClass; if (rocketMQListener != null) { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQListener); } else { targetClass = AopProxyUtils.ultimateTargetClass(rocketMQReplyListener); } Type matchedGenericInterface = null; while (Objects.nonNull(targetClass)) { Type[] interfaces = targetClass.getGenericInterfaces(); if (Objects.nonNull(interfaces)) { for (Type type : interfaces) { if (type instanceof ParameterizedType && (Objects.equals(((ParameterizedType) type).getRawType(), RocketMQListener.class) || Objects.equals(((ParameterizedType) type).getRawType(), RocketMQReplyListener.class))) { matchedGenericInterface = type; break; } } } targetClass = targetClass.getSuperclass(); } if (Objects.isNull(matchedGenericInterface)) { return Object.class; } Type[] actualTypeArguments = ((ParameterizedType) matchedGenericInterface).getActualTypeArguments(); if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) { return actualTypeArguments[0]; } return Object.class; }  long getSuspendCurrentQueueTimeMillis(); void setSuspendCurrentQueueTimeMillis(long suspendCurrentQueueTimeMillis); int getDelayLevelWhenNextConsume(); void setDelayLevelWhenNextConsume(int delayLevelWhenNextConsume); String getNameServer(); void setNameServer(String nameServer); AccessChannel getAccessChannel(); void setAccessChannel(AccessChannel accessChannel); String getConsumerGroup(); void setConsumerGroup(String consumerGroup); String getTopic(); void setTopic(String topic); int getConsumeThreadMax(); String getCharset(); void setCharset(String charset); MessageConverter getMessageConverter(); DefaultRocketMQListenerContainer setMessageConverter(MessageConverter messageConverter); RocketMQListener getRocketMQListener(); void setRocketMQListener(RocketMQListener rocketMQListener); RocketMQReplyListener getRocketMQReplyListener(); void setRocketMQReplyListener(RocketMQReplyListener rocketMQReplyListener); RocketMQMessageListener getRocketMQMessageListener(); void setRocketMQMessageListener(RocketMQMessageListener anno); ConsumeMode getConsumeMode(); SelectorType getSelectorType(); void setSelectorExpression(String selectorExpression); String getSelectorExpression(); MessageModel getMessageModel(); DefaultMQPushConsumer getConsumer(); void setConsumer(DefaultMQPushConsumer consumer); @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(); void setName(String name);  }