skip to Main Content

Redis has very good implementation for PUBSUB where a message published on a channel will be received by multiple receivers registered for the topic.

What is the ideal way to implement point-to-point (i.e. queue) semantics where e.g. multiple receivers are registered with a single queue and as soon as a message is pushed to the queue it will be processed by only 1 receiver (listener)? Any Java reference example would help.

Here the idea is to a read huge file containing transaction records and hence each transaction should be processed only once.

I could see Redis Streams is advised, but I do not see a sound Java reference implementation

2

Answers


  1. Chosen as BEST ANSWER

    Note that there is no direct implementation like for PUBSUB topic . Another reason to use Queue here is that there is no Durable Subscription in Publish Subscribve as well i.e. when subscriber is not up when the message sent your message will be lost. but below Queue implementation would save bit here.
    Final Answer

    LPUSH TEST_QUEUE Test message LLEN TEST_QUEUE BRPOP TEST_QUEUE 0

    Java Implementation

    while(true){
    redisTemplate.opsForList().leftPop("TEST_QUEUE",0, TimeUnit.SECONDS);
    int keySize =this.pushOperation.size("TEST_QUEUE"); 
    //iterate keySize {
    redisTemplate.opsForList().leftPop("TEST_QUEUE",0, TimeUnit.SECONDS);
    }
    }
    

  2. Just use LPUSH msgqueue to put items in the the list and have all clients do:

    while running
        BRPOP msgqueue
        # process popped item
    done
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search