Event sourcing data flows for a simple web application - event-sourcing

Read through a lot of the CQRS/DDD/ES blog posts, still unsure a simple blog engine would work.
In the case of publishing a post, for instance...
User clicks publish → PostPublished event added to Event Store → Triggers the Aggregate Objects (for instance, Archive and FrontPage) to be updated to reflect most recent event.
On the user side, I click the publish button and am redirected to the front page of my blog, where I expect to see the new post on the top. However, if the Event Store is behind (say by 1-2 seconds), my new post will not show up.
Is the answer to have a system that waits for all the Aggregates to be updated before returning the redirect to the user?

Your question is how to deal with eventual consistency, and there really isn't a fool proof one size fits all solution.
The best solution IMO would be to simply put a 'Post published, it will show up in a moment' notification up there. Some people will also do queries over and over until they get the recent change THEN display the front page. Which delays the front page for a second or two if the ES is behind.

Related

Updating multiple tabs with KnockoutJS

My users browse products and add some of them to their baskets.
I use KnockoutJS to update the listing of the basket content.
However, users can open product links on multiple tabs/windows in the same session and pick one product on the first, another product on the second tab. I'd like to display the same basket content on each page, of course.
Is KnockoutJS able to update the DOMs of different tabs simultaneously?
I'd like a solution which updates the changes only, and immediately as KnockoutJS does on a single page. I was mentioning a basket to illustrate the problem, but a basket's content is relatively small and could be retrieved by an AJAX call easily when the user brings up a background tab. The real problem is different views of a huge database, which can be updated in multiple tabs and should look consistent on every tab. It takes several seconds to build up the DOM of a tab.
(This question is NOT about jQuery UI Tabs. The situation is as described in http://thesocialtester.co.uk/20-days-of-web-testing-multiple-tabs-and-windows/)
If the answer is not possible, I'd like to hear about workarounds or good practices.
Thanks in advance.
Knockout does not address the underlying general problem of communicating across browser tabs with javascript. There are other questions on this topic, and the same solutions will be usable with whatever framework you pick.
But no, Knockout makes no attempt to solve this problem.
As stated in the accepted answer, Knockout does not solve the cross-tab problem.
If your problem is strictly confined to the case of synching several tabs in the same browser, then using localStorage to pass messages (as described in this answer cited in the accepted answer seems like a sane solution.
The question is whether you don't really want to go further in solving this problem, and implement some form of server push to your shopping page, which would then also work cross-browser and cross-machine.
In this case, you'd want some solution which uses WebSocket (real server push to the client), possibly combined with a HTTP polling fallback for older browsers (if you need to support those).

Scraping pages that do not seem to have URLs

I'm trying to scrape these listings and provide more exposure for these job listings on a site that belongs to a client of mine. The issue is that I need to be able to link to the specific job listing in order for the job seeker to apply. This is the page I'm trying to save listing links from.
It would be ideal if I could save an address for the job seeker to click on to see the original listing and then apply.
What is this website doing to not feature a URL for these pages
Is it possible to provide a listing specific address
If that's possible how could I generate that address?
If I can't get a specific address I think I could get it so that the user clicks a link that triggers an internal script on my client's site which takes the listing ID and searches the site I found that listing on, and then redirects the user to that specific listing.
The downside to this is that the user will have to wait a little while depending on how far back the listing is on a directory. I could put some kind of progress bar with a pleasant "Searching for your listing! Thanks for being patient" message.
If I can avoid having to do this, though, that'd be great!
I'm using Nokogiri and Mechanize.
The page you refer to appears to be generated by an Oracle product, so one would think they'd be willing to construct a web form properly (and with reference to accessibility concerns). They haven't, so it occurs to me that either their engineer was having a bad day, or they are deliberately making it (slightly) harder to scrape.
The reason your browser shows no href when you hover over those links is that there isn't one. What the page does instead is to use JavaScript to capture the click event, populate a POST form with some hidden values, and call the submit method programmatically. This can cause problems with screen-readers and other accessibility devices, as well as causing problems with the way in which back buttons have to re-submit the page.
The good news is that constructions of this kind can usually be scraped by creating a form yourself, either using a real one on a third party page, or via a crawler library. If you post the right values to the target URI, reverse-engineered from examining the page's script, the resulting document should be the "linked" page you expect.

Implement real-time updating notification feature

I'd like to implement some visual indicator of various sections for the items whose status is pending in my app similar to facebook's / google plus unread notification indicator...I have written an API to fetch the count to be displayed, but I am stuck at updating it everytime an item gets added or deleted, I could think of two approaches which I am not satisfied with, first one being making an API call related to the count whenever a POST or DELETE operation is performedSecond one being refreshing the page after some time span...
I think there should be much better way of doing this from server side, any suggestion or any gem to do so?
Even in gmail it is refreshed on client request. The server calculates the amount of new items, and the client initiates a request (probably with AJAX). This requires an almost negligible amount of data and process time, so probably you can get away with it. Various cache gems even can store the part of the page refreshed if no data changed since last request, which even solves the problem of calculating only when something changed.
UPDATE:
You can solve the problem basically two ways: server side push, and a client side query. The push is problematic, for various reasons, rarely used in web environment, at least as far as I know. Most of the pages (if not all) uses timed query to refresh such information. You can check it with the right tool, like firebug for firefox. You can see as individual requests initiated towards the server.
When you fire a request trough AJAX, the server replies you. Normally it generates a page fragment to replace the old content with the new, but some cache mechanism can intervene, and if nothing changed, you may get the previously stored cache fragment. See some tutorial here, for various gems, one of them may fit your needs.
If you would prefer a complete solution, check Faye (tutorial here). I haven't used it, but may worth a try, seems simple enough.

Why do update streams require the user to manually 'load more content'?

Looking at a lot of web applications (websites/services/whatever) that have a 'streaming' component (typically this is a 'Social' app): Think: Facebook's 'Wall', Twitter 'Feed', LinkedIn's 'News Feed'.
They have a pretty similar characteristic: 'A notice of new items is added to the page (automatically assuming via a background Ajax call', but the new HTML representing the newest feed items isn't loaded to the page until the users click this update link.'
I guess I'm curious if this design decision is for any of the following reasons and if so: could anyone whom has worked on one of these types of apps explain the reasoning they found for doing it this way:
User experience (updates for a large number of 'Facebook Friends' or
'Pages' or 'Tweets' would move too quickly for one to absorb and
read with any real intent, so the page isn't refresh automatically.
Client-side performance: fetching a simple 'count' of updates
requires less bandwidth (less loadtime), less JS running to update
the page for anyone whom has the site open, and thus a lighter
weight feel on the client-side.
Server-side performance: Fewer requests coming into the server to
gather more information about recent updates (less outgoing
bandwidth, more free cycles to be grabbing information for those
whom do request it (by clicking the link). While I'm sure the owners
of these websites aren't 'short on resources', if everyone whom had
Twitter or Facebook open in the browser got a full-update fetched
from the server every-time one was created I'm sure it would be a
much more sig. drag on resources.
They are actually trying to save resources (it takes a cup of coffee
to perform a Google search (haha)) and sending a few bytes of data
to the page representing the count of new updates is a lot lighter
of a load on applications that are being used simultaneously on
hundreds and thousands of browser windows (not to mention API
requests).
I have a few more questions depending on the answer to this first question as well...so I'll probably add those here or ask another question!!
Thanks
P.S. This question got trolled off of the 'Web Applications' site -- so I brought my questions here where they're not to 'broad' or 'off-topic' (-8
Until the recent UI changes to Facebook, they did auto-load new content. It was extremely frustrating from a user perspective, as you'd be reading through the list of your friend's posts and all of a sudden everything would shift and you'd have no idea where the post you were just reading went.
I'd imagine this is the main reason.

How to get data out of entity in script in CRM 2011

I have 2 entities (for this example) in CRM 2011 - Account and Case. The Account holds all of our clients, the case holds individual work actions for an account. When a case is created one of the input fields is the Account.
What I would like to do is upon the user selecting the Account, execute some javascript to look up the account entity to display some additional information.
So far I have got the javascript working that triggers the onchange event of the Account field, and it correctly gets the selected Account, but I don't know what the next step is.
I'm new to CRM so don't really know if what I'm asking is actually sensible, if there is a better way then please let me know.
Thanks!
For the record, the way you were thinking about doing things would be completely supported, and TechHike's method is supported in CRM 4, not CRM 2011. Steps you would take:
Use CRM 2011's web resources to upload a script file that does what you want.
Use the form editor to make your javascript method from step one fire when the Account field changes on the form
Make a request to CRM's REST endpoint (http://msdn.microsoft.com/en-us/library/gg334767.aspx) to retrieve the details of the account selected
Use the results to populate fields on the form, show a popup with details, etc.
There are plenty of examples of caling the REST endpoint from JavaScript in the SDK (http://msdn.microsoft.com/en-us/library/gg309408.aspx). Good luck!
Matt's post above contains everything you need to know, but you might also find the blog post below useful. It basically describes the same scenario where you have a 1:n relationship (such as Case and Account) and details how you can pull information from a specified lookup (e.g. account), using the REST endpoint (as Matt has already mentioned) and display it on the form.
http://community.dynamics.com/product/crm/crmtechnical/b/crminthefield/archive/2011/02/07/showing-related-information-in-a-crm-2011-form.aspx
The blog post includes a link to download a CRM2011 solution already built to give you something to look at how they've achieved this (useful if you're new to CRM2011).
There are two ways to do this, and you may be best to do them both in parallel:
on the Account > Case relationship edit the Mappings. When a user goes to an Account and uses the left navigation to look at Cases (or a grid of Cases on the form) then hits "Add New Case" they are creating a Case from inside the "context" of the Account. You can copy any fields you want to from the Account to the Case record at this point - the Mappings define what field from the Account are copied to which target field on the Case. This will always be the most robust, easiest way to do it but relies on the user starting in the right place.
on the Case for you could also add an onChange script to the Parent Customer lookup to fetch the data from the parent record. I think Stephen's link is probably the best way to do this as it does not copy the fields but allows the user to see them anyway, which is better database design (from a purist standpoint) and means the user always sees current info about the Account rather than possibly out of date stuff. Alternatively if you actually need to copy some fields (maybe the customer's normal SLA say) so that you can use these in other such as scripts or workflows on the Case then have a look at this article: Disabling the selection of contacts for opportunities all the way
Although this is about a slightly different topic, the script there fetches the Account details of the parent Contact - you want to fetch values from a parent (llokup) field so the approach is the same, just different in the detail
There are various ways to do this but I would recommend doing it the supported way, without javascript. This may not be as pretty but it is likely much easier. The scenario would be to add a left navigation link to the case entity that when clicked will update the content area to show the details of the account.
To add a link to the left navigation you will need to configure the isv.config file to have an extra link for the case entity.
Here's an example:
http://support.sfusion.com/kb/hosted-microsoft-crm-4/how-do-i-modify-the-isv-config-file-in-microsoft-crm-4/
You can also lookup isv.config customizations in the SDK, found here:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=82e632a7-faf9-41e0-8ec1-a2662aae9dfb&displaylang=en
Next you will need to create a custom aspx page in the ISV folder of the web server. This page will display all the information about the account that you want to show the user when the left navigation link is clicked. The ISV.config as an xml property that allows you to pass all the context params to your page on the querystring. Make sure when you create the link to turn on this attribute.
Now the only tricky part is that in the page you will need to use the CRM web service to display all the account details that you interested in showing the user. I won't do into details on this. You can find great tutorials on the web or in the SDK if you haven't done this before.

Resources