Skip to content

@RqueueListener Generic results not support  #49

Description

@victory-wu
@Getter
@Setter
public class RqueueResponse<T> {
    private CreatorMerchant owner;
    private T data;
}

@Component
@Slf4j
public class CustomerChangeListener {
    @Autowired
    private CustomerScoreService customerScoreService;

    @RqueueListener(value = TopicConstant.CUSTOMER_INFO_CHANGE)
    public void infoChange(RqueueResponse<CustomerInfo> resp) {         <---- ERROR RESULT
        customerScoreService.updateInfoScore(resp.getData(), resp.getOwner().getMerchantId());
    }
}
@Service
public class RqueueService {
    @Autowired
    private RqueueMessageEnqueuer rqueueMessageEnqueuer;
    @Autowired
    private SaasContext saasContext;

    public <T> void enqueue(String queueName, T message) {
        rqueueMessageEnqueuer.enqueue(queueName, new RqueueResponse<T>(saasContext.getCurrentCreator(), message));
    }
}

ERROR:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.wzx.server.entity.m.CustomerInfo

analysis:

It does not support generic parsing and is converted to LinkHashMap by default

Activity

  1. sonus21 commented on Nov 13, 2020

    @sonus21
    Owner

    yes that's a limitation. Would you mind providing a fix if you know? You need to change GenericMessageConverter class.

  2. victory-wu commented on Nov 16, 2020

    @victory-wu
    Author

    no problem. i need to deal with other work recently. u need to wait

  3. chanmratekoko commented on Jan 21, 2021

    @chanmratekoko

    Hi, @sonus21

    Do the generic results support now?
    How can I implement it?

  4. sonus21 commented on Jan 21, 2021

    @sonus21
    Owner

    Hi @chanmratekoko
    No this does not support generic, generic has issue in deserialisation process, so now you can not even enqueue generic object using Rqueue enqueuer.

    There're some complexity with supporting generic object, in serialisation step we need to track the generic information.

    GenericMessageConverter is responsible for (de)serialisation. You can provide a new implementation of this class in your application to use.

    If your generic class has some fixed generic information then it can be addressed easily but as soon as you start adding more generic data it becomes quite messy. This is the reason most of the library does not support deserialisation correctly event spring-data-redis fail on this.

    Some experimental codes can be seen in this class GenericMessageConverterTest

    Hope you find a universal working soln.

    Play with Gson and see if that works for your use case, then you can use Gson in your code for some of the queues.

  5. victory-wu commented on Jan 22, 2021

    @victory-wu
    Author

    @sonus21
    Hi, long time no see,
    I use Kafka now,

    kafka + spring boot , It's easy to use

    Multiple projects can be implemented alternately

    Many rules supporting spring

    I don't think you should be discouraged, But that's the reality

    Continuing to maintain this project will waste you a lot of time

    @Component
    @Slf4j
    public class CustomerChangeListener {
    
        @KafkaListener(topics = "${spring.profiles}" + KafkaConstant.CUSTOMER_INFO_CHANGE)
        public void infoChange(Long customerId) {
            customerScoreService.updateInfoScore(customerId);
        }
    
        @KafkaListener(topics = KafkaConstant.CUSTOMER_INFO_SCORE_CONFIG_CHANGE)
        public void infoConfigChange(Long ownerMerchantId) {
            customerScoreService.batchUpdateInfoScore(ownerMerchantId);
        }
    }
    
    
    @Component
    @Slf4j
    public class CustomerChangeListener2 {
    
        @KafkaListener(topics = "${spring.profiles}" + KafkaConstant.CUSTOMER_INFO_CHANGE)
        public void infoChange(Long customerId) {
            customerScoreService.updateInfoScore(customerId);
        }
    
        @KafkaListener(topics = KafkaConstant.CUSTOMER_INFO_SCORE_CONFIG_CHANGE)
        public void infoConfigChange(Long ownerMerchantId) {
            customerScoreService.batchUpdateInfoScore(ownerMerchantId);
        }
    }
    
  6. sonus21 commented on Jan 22, 2021

    @sonus21
    Owner

    @victory-wu not sure if your comment is related to other ticket #47

    There're some limitation, give me some more time, I'm working on code to change it to use Redis Stream that's new data structure in Redis.

  7. Repository owner locked and limited conversation to collaborators on Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    limitationThis is a system limitation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions