Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Handler constructer
- ConstructorFunction(bus)
- {
- Bus = bus
- }
- code in the handle function.
- // sent the message to the bus and wait for the reply
- IMessage response = null;
- var synchronousHandle = Bus.Send(service2queue, requestMessage)
- .Register(
- (AsyncCallback)delegate(IAsyncResult asyncResult)
- {
- // Callback block for reply message
- // Reply message received
- NServiceBus.CompletionResult completionResult = asyncResult.AsyncState as NServiceBus.CompletionResult;
- if (completionResult != null && completionResult.Messages.Length > 0)
- {
- // Always expecting one IMessage as reply
- response = completionResult.Messages[0];
- }
- },
- null);
- // block the current thread till the reply received.
- synchronousHandle.AsyncWaitHandle.WaitOne();
- Bus.Send(request).Register(asyncCallback, state)
- Callback only fires on first response, then is cleaned up to prevent memory leaks.
- Doesn’t survive restarts – not suitable for server-side
- service1 gets a notification about messageA
- service1 sends message requestMessage to service2
- service2 replies with message responseMessage to service1
- service1 handles responseMessage and continues processing
Advertisement
Add Comment
Please, Sign In to add comment