Design pattern for getting initial value in pubsub in autobahn

一曲冷凌霜 提交于 2020-01-24 18:25:15

问题


Normally, a publish-subscribe pattern is about fetching content updates. But how do subscribers get initial content that was there before they subscribed for updates?

I'm using publish-subscribe examples within autobahn framework for my application. The publisher backend publishes a position of the robotic joint when the joint moves. The client frontend subscribes to the topic sometimes later. Due to the nature of the data, the initial value of the "topic" on the client is just as important as subsequent updates made by the publisher. So right after a successful connection is established, I'd like to fetch the "current" value of the topic.

Is there some type of design pattern within the framework that I can leverage to get the "current" value (the value prior to subscription)? I can think of some sort of separate RPC service for fetching it, but it seems that it will be going through a separate delivery channel. Ideally, I would want for the publisher to notice that I just subscribed and push the initial value to the individual client, or something of that sort, but that might be too much to ask, or is it not?


回答1:


Ideally, I would want for the publisher to notice that I just subscribed and push the initial value to the individual client

This is a pefectly fine use case and desired behavior .. in fact, it's on the feature list for the WAMP Advanced Profile: https://github.com/tavendo/WAMP/issues/69

This seems sufficiently clearly defined already and isn't particular hard to implement in routers .. but it needs code in the routing core.




回答2:


A simpler alternative: create a DB frontend subscriber component to your topic that is always subscribed, storing time series of the topic values. Your front end client queries your DB and pulls whatever pre-subscription topic values you need. You now have your initial values and the current real time subscription values.

I'd argue providing this functionality in the router is overkill. Just have your DB be a subscriber and hook in the pre-subscribe fetch logic to your subscriber component. Sure it puts the DB in as an exchange point but only on historical (non real time), and as the feature list describes anyway, if a DB subscriber is not logging the pre-subscription value then the router must. Also prevents the router from looking/feeling like a persistence store, that is not its job.

Edit: Kraken does essentially this: it pulls from the DB the last bit of topic changes and upon each new subscription syncs that historical and the real time.

http://asana.github.io/kraken/. Applications use Kraken to transmit and receive messages through topics. These messages will typically contain just enough information to identify the set of data that was changed by the client just before the message was published. When other clients receive these messages, they will figure out which data changed and reload it from the datastore so that they are eventually brought up to date.




回答3:


At least crossbar makes it now possible to retrieve the latest published value when subscribing.

You need to enable the in-memory event history and request retained events.

Here you can find an example for autobahn-python: https://github.com/crossbario/autobahn-python/commit/c8eddd653fe77fc00cbbcfc395f3a1d0be88cd1b



来源:https://stackoverflow.com/questions/27641630/design-pattern-for-getting-initial-value-in-pubsub-in-autobahn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!