You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/06/30 06:01:50 UTC

[GitHub] [rocketmq] novicate opened a new issue, #4535: RocketMQListener generic

novicate opened a new issue, #4535:
URL: https://github.com/apache/rocketmq/issues/4535

   abstract static class BaseMQ<T> implements RocketMQListener<T> {
   }
   
   @RocketMQMessageListener(topic=xxx, consumerGroup=xxx)
   class Consumer extend BaseMQ<Entity> {
   }
   
   I'm going to use the BaseMQ class to provide template methods, but it throws exception:
   
   Caused by: java.lang.RuntimeException: parameterType:T of onMessage method is not supported
   	at org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer.getMethodParameter(DefaultRocketMQListenerContainer.java:499)
   	at org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer.afterPropertiesSet(DefaultRocketMQListenerContainer.java:319)
   	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
   	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] Oliverwqcwrw commented on issue #4535: RocketMQListener generic

Posted by GitBox <gi...@apache.org>.
Oliverwqcwrw commented on issue #4535:
URL: https://github.com/apache/rocketmq/issues/4535#issuecomment-1171903170

   Hi @novicate ,
   
   there have three advises and hope these can help you
   1. abstract class can not be definition to static
   2. extend should be extends
   3. The Consumer should `Override` onMessage method
   
    Have a great day!
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] RocketMQListener generic [rocketmq]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed issue #4535: RocketMQListener generic
URL: https://github.com/apache/rocketmq/issues/4535


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] Oliverwqcwrw commented on issue #4535: RocketMQListener generic

Posted by GitBox <gi...@apache.org>.
Oliverwqcwrw commented on issue #4535:
URL: https://github.com/apache/rocketmq/issues/4535#issuecomment-1172178538

   Could you please provide more detailed log about application starting?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] RocketMQListener generic [rocketmq]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #4535:
URL: https://github.com/apache/rocketmq/issues/4535#issuecomment-1817683675

   This issue is stale because it has been open for 365 days with no activity. It will be closed in 3 days if no further activity occurs.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] novicate commented on issue #4535: RocketMQListener generic

Posted by GitBox <gi...@apache.org>.
novicate commented on issue #4535:
URL: https://github.com/apache/rocketmq/issues/4535#issuecomment-1172143007

   I'm sorry for my poor spelling.
   What I'm trying to say is: 
       If I configure like this, my project won't start.
   
   public class BaseRocketMQConsumer<T> implements RocketMQListener<T> {
       @Override
       public void onMessage(T message) {
           beforeConsume();
           doConsume();
           afterConsume();
       }
   }
   
   @RocketMQMessageListener(topic=xxx, consumerGroup=xxx)
   public class ConsumerA extends BaseRocketMQConsumer<Entity> {
   }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] QingXSummer commented on issue #4535: RocketMQListener generic

Posted by GitBox <gi...@apache.org>.
QingXSummer commented on issue #4535:
URL: https://github.com/apache/rocketmq/issues/4535#issuecomment-1312692983

   I had the same problem。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] caizhenghao commented on issue #4535: RocketMQListener generic

Posted by GitBox <gi...@apache.org>.
caizhenghao commented on issue #4535:
URL: https://github.com/apache/rocketmq/issues/4535#issuecomment-1236376248

   I met this exception too. After I read the code in DefaultRocketMQListenerContainer.getMethodParameter,I think it not a bug but a problem in usage.I change my code and avoid this problem.I hope it can be helpful.
   
   public abstract class AbstractBaseListener<T> implements RocketMQListener<MessageExt> {
       private final Type msgBodyType;
   
       public AbstractBaseListener() {
           Type typeAbstractListener = this.getClass().getGenericSuperclass();
           Type[] actualTypeArguments = ((ParameterizedType) typeAbstractListener).getActualTypeArguments();
           if (Objects.nonNull(actualTypeArguments) && actualTypeArguments.length > 0) {
               msgBodyType = actualTypeArguments[0];
           } else {
               throw new IllegalStateException("can not explain the object");
           }
       }
   
       @Override
       public void onMessage(MessageExt messageExt) {
           String bodyStr = new String(messageExt.getBody(), Charset.forName("UTF-8"));
           Object msgBody;
           if (msgBodyType == String.class) {
              msgBody = bodyStr;
           } else {
              msgBody = JSON.parseObject(bodyStr, msgBodyType);
           }
          doConsume((T) msgBody);
     }
   }
   
   @RocketMQMessageListener(topic=xxx, consumerGroup=xxx)
   public class ConsumerA extends AbstractBaseListener<Entity> {
   
   }
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] enson16855 commented on issue #4535: RocketMQListener generic

Posted by GitBox <gi...@apache.org>.
enson16855 commented on issue #4535:
URL: https://github.com/apache/rocketmq/issues/4535#issuecomment-1319425928

   I had the same problem。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] RocketMQListener generic [rocketmq]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #4535:
URL: https://github.com/apache/rocketmq/issues/4535#issuecomment-1823679233

   This issue was closed because it has been inactive for 3 days since being marked as stale.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org