asp.net mvc - Synchronizing my records between two separate databases -
i building bpm based on asp.net mvc, working on 2 systems:-
a third party bpm.
my own bpm system.
currently when adding new process doing following:-
- create new process @ third party application using rest api.
- create new process @ own bpm database.
but facing following problems:-
- how can add/edit/delete records 2 systems consistence manner, if record not added in third party system have remove system, , visa versa.
my process model class is:-
public class newprocess { public string name { get; set; } public string activityid { get; set; } public string status {get; set;} }
my action method is:-
[httppost] public actionresult createprocess(string name) { using (var client = new webclient()) { try { repository.createprocess(name,"pending"); repository.save(); var query = httputility.parsequerystring(string.empty); query["j_username"] = "kermit"; query["hash"] = "9449b5abcfa9afda36b801351ed3df66"; query["loginas"] = user.identity.name; var url = new uribuilder("http://localhost:8080/jw/web/json/process/create/" + name.tostring() ); url.query = query.tostring(); string json = client.downloadstring(url.tostring()); var serializer = new javascriptserializer(); var myobject = serializer.deserialize<newprocess>(json); string activityid = myobject.activityid; if (activityid != null) { repository.updateprocess(name, "finish"); repository.save(); }
so doing inside post action method, :-
- create new record @ database status of “pending”.
- calling third party api, , result.
- if activityid not null (the create successes in third party system), updating record status “finish”. else status stay pending.
- i have built screen display records status “pending” , , admin able delete them own database.
so approach work , or create problems unaware of . or should looking different approach
thanks in advance help.
the direction looks ok. remember complete cycle , consider few more options
based on statement "what doing"
1 create new record @ database status of “pending”.
2 calling third party api, , result.
3 if activityid not null (the create successes in third party system), updating record status “finish”. else status stay pending.
4 have built screen display records status “pending” , , admin able delete them own database.
you have covered main concept of 2 staged commit. , if goes fine. should consider.
investigate if theory point of view "reliable messaging". may overkill here.
- what if dont receive reply. cant assume wasnt posted. return traffic may lost post commit on other side. should follow check exists calls or manually tidy up.you need posting sides entry rather deleting everytime there not response. delete of course likely. of course im not talking side receives message not posted. clear known state.
what happens if pending finished change commit fails? how recover situation. delete otherside entry? or retry yourside.
you should consider basic pattern/plan when other side not reachable @ all. accept posts, record many pending , have process retries pending records later. or fail new calls until other party reachable. @ least think non perfect world scenarios , have plan.
that basic pattern. , doing of manually ok. plan , valid pattern. of course can add tools, , logic support this. eg error handling, automated retry patterns. asynchronous acknowledgements etc. taking enterprise level. @ enterprise cost.
basically if take stance 1 system responsible overall integrity , ongoing synchronization. best place start. have that. system orchestrator , responsible synchronization outcomes.
Comments
Post a Comment