You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "kevinWangSheng (via GitHub)" <gi...@apache.org> on 2024/08/09 12:37:18 UTC

[D] [Bug] Use the plusar and spring aop ,the aop failed [pulsar]

GitHub user kevinWangSheng created a discussion: [Bug] Use the plusar and spring aop ,the aop failed

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.


### Read release policy

- [X] I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.


### Version

windwos 10 64x
jdk8
pulsar:2.1

### Minimal reproduce step

 does it support spring aop ?

### What did you expect to see?

i want to go to the aspcet 

@Pointcut("@within(com.ak.cepf.mybatis.aspect.IgnoreTenant) ||@annotation(com.ak.cepf.mybatis.aspect.IgnoreTenant)")
    public void pointcut() {
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object var9;
        try {
            Class<?> targetClass = point.getTarget().getClass();
            IgnoreTenant classIgnoreTenant = (IgnoreTenant)targetClass.getAnnotation(IgnoreTenant.class);
            MethodSignature signature = (MethodSignature)point.getSignature();
            Method method = signature.getMethod();
            IgnoreTenant methodIgnoreTenant = (IgnoreTenant)method.getAnnotation(IgnoreTenant.class);
            boolean isClassAnnotated = AnnotationUtils.isAnnotationDeclaredLocally(IgnoreTenant.class, targetClass);
            boolean isMethodAnnotated = Objects.nonNull(methodIgnoreTenant);
            if (isClassAnnotated) {
                MybatisTenantContext.set(classIgnoreTenant.isIgnore());
            }

            if (isMethodAnnotated) {
                MybatisTenantContext.set(methodIgnoreTenant.isIgnore());
            }

            var9 = point.proceed();
        } finally {
            MybatisTenantContext.clear();
        }

        return var9;
    }
    
    
    and config like that :
    
    
    @PulsarConsumer(topic = "cepf_listing_change",
            subscriptionName = "cepf_statistics",
            serverName = "amsPulsar",
            clazz = byte[].class,
            initialPosition = SubscriptionInitialPosition.Latest,
            serialization = Serialization.BYTE,
            deadLetterTopic = "cepf_listing_change-dlq",
            maxRedeliverCount = 3
    )
    // 不走租户
    @IgnoreTenant
    // todo 消费供货价改变消息
    public void consumeSupplyPriceChangeMessage(PulsarMessage<byte[]> message){
        try {
            log.info("[orderItemPriceChange] messageId:{},message{}",message.getMessageId(),message);
            MessageDTO messageDto = JSONObject.parseObject(message.getValue(), MessageDTO.class);
            if(ObjectUtil.isEmpty(messageDto)){
                return;
            }
            supplyPriceChangeRepairService.repairItemsCommonPriceAmount(messageDto);
        } catch (Exception e) {
            // 放到死信队列进行重试
            log.warn("[orderItemPriceChange] 消费失败,进行重试:{}", JSON.toJSONString(message));
            e.printStackTrace();
            throw e;
        }
    }
    
    the PulsarConsumer is depend on pulsar

### What did you see instead?

I debug and don't see go to the code:
@Pointcut("@within(com.ak.cepf.mybatis.aspect.IgnoreTenant) ||@annotation(com.ak.cepf.mybatis.aspect.IgnoreTenant)")
    public void pointcut() {
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object var9;
        try {
            Class<?> targetClass = point.getTarget().getClass();
            IgnoreTenant classIgnoreTenant = (IgnoreTenant)targetClass.getAnnotation(IgnoreTenant.class);
            MethodSignature signature = (MethodSignature)point.getSignature();
            Method method = signature.getMethod();
            IgnoreTenant methodIgnoreTenant = (IgnoreTenant)method.getAnnotation(IgnoreTenant.class);
            boolean isClassAnnotated = AnnotationUtils.isAnnotationDeclaredLocally(IgnoreTenant.class, targetClass);
            boolean isMethodAnnotated = Objects.nonNull(methodIgnoreTenant);
            if (isClassAnnotated) {
                MybatisTenantContext.set(classIgnoreTenant.isIgnore());
            }

            if (isMethodAnnotated) {
                MybatisTenantContext.set(methodIgnoreTenant.isIgnore());
            }

            var9 = point.proceed();
        } finally {
            MybatisTenantContext.clear();
        }

        return var9;
    }

### Anything else?

i guess it doesn't support spring aop ?
i know it's threapool is not registry to spring? 
so i doesn't support it?
i want to know why.

### Are you willing to submit a PR?

- [X] I'm willing to submit a PR!

GitHub link: https://github.com/apache/pulsar/discussions/23148

----
This is an automatically sent email for commits@pulsar.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@pulsar.apache.org


Re: [D] Use the pulsar and spring aop ,the aop failed [pulsar]

Posted by "kevinWangSheng (via GitHub)" <gi...@apache.org>.
GitHub user kevinWangSheng edited a discussion: Use the pulsar and spring aop ,the aop failed

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.


### Read release policy

- [X] I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.


### Version

windwos 10 64x
jdk8
pulsar:2.1

### Minimal reproduce step

 does it support spring aop ?

### What did you expect to see?

i want to go to the aspcet 

@Pointcut("@within(com.ak.cepf.mybatis.aspect.IgnoreTenant) ||@annotation(com.ak.cepf.mybatis.aspect.IgnoreTenant)")
    public void pointcut() {
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object var9;
        try {
            Class<?> targetClass = point.getTarget().getClass();
            IgnoreTenant classIgnoreTenant = (IgnoreTenant)targetClass.getAnnotation(IgnoreTenant.class);
            MethodSignature signature = (MethodSignature)point.getSignature();
            Method method = signature.getMethod();
            IgnoreTenant methodIgnoreTenant = (IgnoreTenant)method.getAnnotation(IgnoreTenant.class);
            boolean isClassAnnotated = AnnotationUtils.isAnnotationDeclaredLocally(IgnoreTenant.class, targetClass);
            boolean isMethodAnnotated = Objects.nonNull(methodIgnoreTenant);
            if (isClassAnnotated) {
                MybatisTenantContext.set(classIgnoreTenant.isIgnore());
            }

            if (isMethodAnnotated) {
                MybatisTenantContext.set(methodIgnoreTenant.isIgnore());
            }

            var9 = point.proceed();
        } finally {
            MybatisTenantContext.clear();
        }

        return var9;
    }
    
    
    and config like that :
    
    
    @PulsarConsumer(topic = "cepf_listing_change",
            subscriptionName = "cepf_statistics",
            serverName = "amsPulsar",
            clazz = byte[].class,
            initialPosition = SubscriptionInitialPosition.Latest,
            serialization = Serialization.BYTE,
            deadLetterTopic = "cepf_listing_change-dlq",
            maxRedeliverCount = 3
    )
    // 不走租户
    @IgnoreTenant
    // todo 消费供货价改变消息
    public void consumeSupplyPriceChangeMessage(PulsarMessage<byte[]> message){
        try {
            log.info("[orderItemPriceChange] messageId:{},message{}",message.getMessageId(),message);
            MessageDTO messageDto = JSONObject.parseObject(message.getValue(), MessageDTO.class);
            if(ObjectUtil.isEmpty(messageDto)){
                return;
            }
            supplyPriceChangeRepairService.repairItemsCommonPriceAmount(messageDto);
        } catch (Exception e) {
            // 放到死信队列进行重试
            log.warn("[orderItemPriceChange] 消费失败,进行重试:{}", JSON.toJSONString(message));
            e.printStackTrace();
            throw e;
        }
    }
    
    the PulsarConsumer is depend on pulsar

### What did you see instead?

I debug and don't see go to the code:
@Pointcut("@within(com.ak.cepf.mybatis.aspect.IgnoreTenant) ||@annotation(com.ak.cepf.mybatis.aspect.IgnoreTenant)")
    public void pointcut() {
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object var9;
        try {
            Class<?> targetClass = point.getTarget().getClass();
            IgnoreTenant classIgnoreTenant = (IgnoreTenant)targetClass.getAnnotation(IgnoreTenant.class);
            MethodSignature signature = (MethodSignature)point.getSignature();
            Method method = signature.getMethod();
            IgnoreTenant methodIgnoreTenant = (IgnoreTenant)method.getAnnotation(IgnoreTenant.class);
            boolean isClassAnnotated = AnnotationUtils.isAnnotationDeclaredLocally(IgnoreTenant.class, targetClass);
            boolean isMethodAnnotated = Objects.nonNull(methodIgnoreTenant);
            if (isClassAnnotated) {
                MybatisTenantContext.set(classIgnoreTenant.isIgnore());
            }

            if (isMethodAnnotated) {
                MybatisTenantContext.set(methodIgnoreTenant.isIgnore());
            }

            var9 = point.proceed();
        } finally {
            MybatisTenantContext.clear();
        }

        return var9;
    }

### Anything else?

i guess it doesn't support spring aop ?
i know it's threapool is not registry to spring? 
so i doesn't support it?
i want to know why.

### Are you willing to submit a PR?

- [X] I'm willing to submit a PR!

GitHub link: https://github.com/apache/pulsar/discussions/23148

----
This is an automatically sent email for commits@pulsar.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@pulsar.apache.org


Re: [D] Use the pulsar and spring aop ,the aop failed [pulsar]

Posted by "kevinWangSheng (via GitHub)" <gi...@apache.org>.
GitHub user kevinWangSheng added a comment to the discussion: Use the pulsar and spring aop ,the aop failed

Is pulsar doesn't support the thread registry to spring?Does anyone know that? please help me, I would appreciate that;

GitHub link: https://github.com/apache/pulsar/discussions/23148#discussioncomment-10287815

----
This is an automatically sent email for commits@pulsar.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@pulsar.apache.org


Re: [D] [Bug] Use the plusar and spring aop ,the aop failed [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
GitHub user lhotari added a comment to the discussion: [Bug] Use the plusar and spring aop ,the aop failed

I migrated this to a GitHub Discussion since this is not a bug in Apache Pulsar.

GitHub link: https://github.com/apache/pulsar/discussions/23148#discussioncomment-10286296

----
This is an automatically sent email for commits@pulsar.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@pulsar.apache.org