question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to publish without subscriber with historical message?

See original GitHub issue

After some testing with both pub/sub and xadd/xread I have came to a situation where I have realized that if my subscriber is not on, the message will not be recieved whenever I start up the subscriber. e.g. situation

  1. You send a message via publish
  2. You turn on your subscriber and listen for the channel 10 seconds after you have send the message via publish
  3. The message will be lost.

There is two different codes that I have tried e.g.

Sub.py

from walrus import *
import time
from config import configuration

client = Walrus(
    host=configuration.helheim.redis_host,
    port=configuration.helheim.redis_port,
    db=configuration.helheim.redis_database
)

stream = client.Stream('sns')

while True:
    test = stream.read()
    print(test)
    # How to delete after read?
    time.sleep(3)

Pub.py

from walrus import *

from config import configuration

client = Walrus(
    host=configuration.helheim.redis_host,
    port=configuration.helheim.redis_port,
    db=configuration.helheim.redis_database
)

stream = client.Stream('sns')

test = stream.add({"status": "start", "link": "https://www.sneakersnstuff.com/sv/product/49769/salomon-xa-alpine-mid-advanced"})
print(test)


Sub.py

    EVENT_LISTENER.subscribe("sns")
    
    while True:
        message = EVENT_LISTENER.get_message()
    
        if message and not message['data'] == 1:
            message = json.loads(message['data'])

Pub.py

    import redis
    
    from config import configuration
    
    client: redis = redis.Redis(
        host=configuration.helheim.redis_host,
        port=configuration.helheim.redis_port,
        db=configuration.helheim.redis_database
    )
    
    channel = "sns"
    client.publish(channel,
                   '{"status": "kill", "store": "sns", "link": "https://www.sneakersnstuff.com/sv/product/49769/salomon-xa-alpine-mid-advanced"}')

and it seems like there is no persist historical messages saved in the redis.

My question is, how am I able to read the messages that I have publish and remove after a read when I have turned on my subcriber?

Hopefully you guys wont me mad at me for asking this question! 😦

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
coleifercommented, Aug 7, 2021

Streams are similar but for your usage I think using lists is the “correct” approach. You’re not using any of the stream-specific functionality, you’ve just implemented a more hacky version of the list push/pop (in my opinion).

1reaction
BarryThrillcommented, Aug 7, 2021

Streams are similar but for your usage I think using lists is the “correct” approach. You’re not using any of the stream-specific functionality, you’ve just implemented a more hacky version of the list push/pop (in my opinion).

Indeed and I agree! I appreciate your help and answer! It means alot for me and I wish you a nice day and evening!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Question] How to publish without subscriber with historical ...
The message will be lost. There is two different codes that I have tried e.g. ... and it seems like there is no...
Read more >
python 3.x - How to publish without subscriber - Stack Overflow
My question is, how am I able to read the messages that I have publish and remove after a read when I have...
Read more >
The publish-subscribe pattern: garbage-collecting old ...
1 Answer 1 · Do not guarantee delivery. · Keep a log of all messages, and let subscribers request re-transmission of all messages...
Read more >
Get message published before subscriber start - ROS Answers
I created the subscription with a QoS History depth of 10 (according to the documentation), but this message is not retrieved (but QoS ......
Read more >
Replaying and purging messages | Cloud Pub/Sub ...
Configuring a topic with message retention gives you more flexibility, allowing any subscription attached to the topic to seek back in time and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found