Comments (6)
Hey @preslavrachev!
Some Pub/Subs may support this. I know RabbitMQ has a plugin for delayed messages, I’ve been using it fot message retries.
But frankly, I think the best way would be to create a separate component for this. It could implement the Publisher and Subscriber interfaces, so you can use it plug-and-play with Watermill.
The publisher would just save the message in the storage, along with the desired publish time (could be a metadata or context field). The subscriber would filter the messages based on the current time. It should be quite easy to implement on top of the SQL Pub/Sub, but that’s not ideal if you don’t use a database at the moment.
What do you think?
from watermill.
@m110 funny you mention SQL, because this is exactly what I set out to use :) May app is fairly small at the moment, and the heavy weightlifting is done by another service. My idea was to introduce persistent messaging as a form of retrial, in case something in any of the use cases goes wrong. A real message queue is more or less something I did not want to manage at the moment.
Anyway, I had a look at the DefaultPostgreSQLSchema
and I saw that everything about creating the tables, inserting and querying is there in one place. I suppose, I could shamelessly copy it, and add support for a date in the future (which may be tucked somewhere in the Message
metadata).
I'll report on my success. Expect a nice blog post about my experience with Watermill if it works out fine ;)
from watermill.
@preslavrachev That’s sounds like a great fit then! 👍 It should be straightforward - you just need to provide a schema adapter based on the default one. If you feel like contributing, this could be added to watermill-sql.
from watermill.
@m110 I was able to add delayed message sending - it was not difficult at all (I guess, that speaks to Watermill's extensibility)!
We can think of contributing the adapter changes to watermill-sql, of course. My only problem is the following - adding the delay right now happens as part of adding a message metadata field. This field is then read before inserting and if present, the future execution gets stored in a separate column. I want to somehow avoid confusing people who would think that delayed messages work with every adapter, and then wonder why those get executed right away.
Let us think about some more edge cases like that. Otherwise, I'd be happy to contribute.
from watermill.
Great to hear that @preslavrachev! 🙌
One idea I can think of is exposing a public function like msg = sql.WithDelay(msg, time.Hour)
with a doc saying it works only with a specific adapter. It could also add a context field if you don’t want to modify the metadata, as the insert is done before any network transfer, so all context fields will be there.
from watermill.
In my situation, I utilize Redis zset for handling 'delayed messages.' Since zset doesn't support 'consumer groups,' I move the messages from the zset to RabbitMQ using a router. You can check out an example at: https://github.com/stong1994/watermill-rediszset/tree/main/example/timer
from watermill.
Related Issues (20)
- s
- MaxOutstandingMessages doesn't seem to be working
- follow-up handler will be broke while before msg handler error, what is the best practice for this situation?
- `msg.Nack` causes infinite loop with gochannel pubsub HOT 4
- Publish message processing delay in metrics Middleware?
- How to subscribe to all gochannel ? HOT 1
- Any plans to add support of RabbitMQ Streaming?
- Generated topic names for PubSub tests does not conform with Azure guidelines
- How to delete message after ack? HOT 1
- Context not being propagated through command bus HOT 2
- Is it possible to get google pubsub server generated unique message-id? HOT 3
- Data race on Publish for Google pubsub
- SQLite driver HOT 4
- Log custom fields inside message router
- Invalid publisher name in metrics
- Resume after shutdown always fetch last interrupted message again
- How to process a batch of received messages instead of a single piece?
- Can you output the message metadata to the logs?
- Only post messages after subscribing
- Watermill tests fail on windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from watermill.