-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Durability #69
Comments
Yep - definitely sounds like good plugin material. I've had a few situations where I've manually rolled something similar (all ugly, unfortunately). I'll try and take a stab at postal.durable soon, then :-) |
@ifandelse Awesome! Thank you! |
@estaylorco - quick question: do you see any messages marked to be preserved as being kept around (indefinitely or within a timeout window, if applicable) for any new subscribers on that channel/topic - or was your use case one where the message wasn't kept around any longer once a subscriber came into the picture? |
@ifandelse My use case referred to any new subscriber on that channel and topic. I suppose if I had to narrow it down, I could use the constraints feature of postal. |
Played around with a very rough idea around this tonight: http://jsfiddle.net/ifandelse/KDaLB/ |
@ifandelse I just went over the code: Brilliant in its simplicity! What I see, too, is that between wiretapping and subscribing |
@ifandelse It just occurred to me: I think it necessary to make it clear at both the point of publishing and at the point of subscribing that we're engaging durability. The subscriber should have to acknowledge that it is interested in durable (preserved) messages. So, for example, at the time of publishing, we have
On the latter note, processing of preserved messages becomes a silent feature of the application if we don't have If a subscriber does not enlist in preserved messages, postal falls back to its default behavior, a behavior everyone should be familiar with if he's adopted postal as part of his application's backbone. [EDIT] I would perhaps modify
Then, later:
This could even be handled with promises, where standby causes the return of a promise that is later resolved on the subscription. Just some thoughts. |
@estaylorco definitely agree it should be an opt-in thing on the part of the subscriber as well. To answer your earlier question "Are wiretapping and after artifacts of your test harness, or is that how you intend to fold the feature into a plugin?" Wiretapping is supported already via postal.addWireTap, and it seems like the ideal place to listen for messages marked with particular flags, since any add-ons could tap there. The var pred = function (data, env) {
return boolCondition;
}
var subscription = channel.subscribe('blah', callback)
.before(function (next, data, envelope) {
if (pred.call(this, data, envelope)) {
next.call(this, data, envelope);
}
}); (The I thought long and hard on this, since AOP is often a super painful footgun. :-) So far it seems to be working out well. All that being said - I think I'd roll this with ConduitJS behavior being applied to Once I do that, I should be able to roll the add-on with the behavior we've discussed pretty easily... (famous last words?) |
@ifandelse You know, when I read the code on your jsFiddle, I noticed AOP makes so much sense here. I grew up in web technologies using Spring on the Java side. We embrace AOP as a way of life there. I was actually looking recently for a client-side AOP framework for JavaScript. I was unaware of Conduit, or perhaps I was aware but just didn't associate it with AOP. Well-written and well understood AOP is incredibly powerful. It should be fine with anybody to depend on low-level frameworks. It just means that, as a dev, you have to "own" those frameworks, in a manner of speaking, make sure you understand the codebase, contribute to that framework's community and ecosystem. As for high-level frameworks, I don't know. Where's the fun? I use Durandal precisely because it is low-level and gets out of my way when I need it to. To each his own, I'd say. |
@ifandelse Just some additional thoughts on the notion of 'standby'. Below is a use case that might help to understand how standby would influence a client of postal.durable (activate, attached, and compositionComplete are all lifecycle events on a Durandal viewmodel, which you can hook into):
The ability to stand by allows proper separation of concerns. I'm free to register subscriptions that are both durable and non-durable, or in the case of the former, whose interest in preserved messages is immediate, rejected, or standby, in a single method: Then, I can enlist when I'm ready (for me, it would be in the Finally, I see a potential problem with using promises in this case. We go back to having to hold on to subscriptions through specific variables, or through an array-push, which is what I was advocating getting away from with my request for additional utils, just so we can resolve or reject the promises. |
Still digesting the last bit above - I took the fiddle and made it into a fledgling project: https://github.com/postaljs/postal.preserve. I'll think through the points you made about "standby" above and see if I come with anything that works well... |
@ifandelse That looks great! Simple. I like the use of headers to convey durability. This takes us very close to the Durable Subscriber pattern. It would seem at this point that you're asking the subscriber to always enlist if the subscriber is interested. That might actually be a better approach. Going back to my post on 'enlist', 'reject' and 'standy', through the single approach you illustrate in your fiddle, we have the following:
The second item above is self-explanatory: Never calling Finally, expired messages should be deleted from the store. |
I've just come across a situation where durability has moved to the forefront.
In Durandal, often we compose views. The
activate
handler of a viewmodel is the best place to set up postal subscriptions. Many times, however, a parent view will publish a message to one or more of its children, but the child, or children, isn't ready yet.It would be nice if messages could be marked "durable" so that when a subscriber subscribes, postal checks to see if there are any messages waiting for that subscriber (on that subscriber's channel and topic). Of course, we would need to be able to configure a timeout. One could even use postal.request-response and its promise to get back a fail after a timeout period. Another option could be to configure a timeout message to publish on some hard-coded channel and topic.
I solved the problem temporarily with a client-side queue. But this seems ideal for incorporation into postal--maybe not into core, but certainly as, say, postal.durable.
The text was updated successfully, but these errors were encountered: