Created
January 7, 2012 04:13
-
-
Save jmarnold/1573762 to your computer and use it in GitHub Desktop.
Correlating requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RequestCorrelation : IConfigurationAction | |
{ | |
public void Configure(BehaviorGraph graph) | |
{ | |
graph | |
.Behaviors | |
.Each(chain => chain.Prepend(new Wrapper(typeof(SetCorrelationHeaders)))); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SetCorrelationHeaders : BasicBehavior | |
{ | |
public const string Correlation_Id = "X-Correlation-Id"; | |
private readonly IRequestHeaders _headers; | |
private readonly IOutputWriter _writer; | |
public SetCorrelationHeaders(IRequestHeaders headers, IOutputWriter writer) | |
: base(PartialBehavior.Ignored) | |
{ | |
_headers = headers; | |
_writer = writer; | |
} | |
protected override DoNext performInvoke() | |
{ | |
_headers.Value<string>(Correlation_Id, id => _writer.AppendHeader(Correlation_Id, id)); | |
return DoNext.Continue; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var pendingRequests = []; | |
var updateRequests = function () { | |
$('#PendingRequests').val(pendingRequests.length); | |
}; | |
amplify.subscribe('AjaxStarted', function(request) { | |
pendingRequests.push(request); | |
updateRequests(); | |
}); | |
amplify.subscribe('AjaxCompleted', function(request) { | |
var id = request.correlationId; | |
var tmpRequests = []; | |
for(var i = 0; i < pendingRequests.lenght; i++) { | |
var r = pendingRequests[i]; | |
if(r.correlationId != id) { | |
tmpRequests.push(r); | |
} | |
} | |
pendingRequests.length = 0; | |
pendingRequests = tmpRequests; | |
updateRequests(); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment