I am using the RPC pattern with RabbitMQ to make client calls to a service that responds back on the TempQueueName. I pass some header information in the RabbitMQ Message Meta collection that I then use to create a basic request with header fields (from Meta) to call the service on the ServiceStack server.
When the service on the server handles the request fine the response object is populated and returned through the queues to the client.
Problem is when I have an error happen and want to return the Error Code and Message back to the client. In my registered processMessageFN method I create and return an error response, but the client is returned the Message object without the Error object property set. And the ResponseDTO object in the body has all members set to null. I’ve tried a number of things, but haven’t found a way to return an error code and message in the Message object back to the client. I do not want to add error fields to each response dto as they are used with other hosts. Any help or direction would be greatly appreciated!
CLIENT CODE…
private void CallMQ()
{
IMessage<R> responseMsg;
mqClient.Publish((new Message<T>(request) { ReplyTo = replyMQ
}).PopulateMeta(this.Request));
responseMsg = mqClient.Get<R>(replyMQ, TimeSpan.FromSeconds(WaitInSeconds));
mqClient.Ack(responseMsg);
//At this point responseMsg.Error is set to null and body's response dto has null members.
}
SERVER CODE…
public override object OnServiceException(IRequest httpReq, object request, Exception ex)
{
//Log some errors...
return null;
}
//Registered processMessageFN
private object ProcessServiceCall<T>(IMessage<T> msg)
{
//Creates a request and populates header from meta collection
var request = new BasicRequest { Verb = HttpMethods.Post }.PopulateRequest(msg as Message);
var response = this.ServiceController.ExecuteMessage(msg, request);
if (response.IsErrorResponse())
{
HttpError error = (HttpError)response;
//*NOTE - I validate error field is populated.
return ServiceStack.HttpResultUtils.CreateErrorResponse(error);
}
return response;
}