Building the Query (Request) Message
In the C# API, as in JMS, the MessageListener delegate receives messages asynchronously. In this example, the delegate OnMessage is called whenever the server receives a customer request message. This implementation of ServerApplication.OnMessage() copies, from the request message, the customer information needed to make the database query. It then issues the query and builds the reply message, calling ConstructReplyMessage() to map data from the customer record to the reply message fields. The following code from OnMessage() shows these steps.
{
try {
IMessage reply;
String command = message.GetStringProperty
(ApplicationConstants.COMMAND_PROPERTY);
Console.WriteLine("OnMessage::Received a command " + command);
if (command.Equals(ApplicationConstants.CUSTOMER_QUERY_COMMAND,
StringComparison.InvariantCultureIgnoreCase)) {
try {
if (message is IMapMessage) {
IMapMessage queryMsg = (IMapMessage) message;
String firstName = queryMsg.GetString
(ApplicationConstants.FIRST_NAME_FIELD);
String lastName = queryMsg.GetString
(ApplicationConstants.LAST_NAME_FIELD);
String location = queryMsg.GetStringProperty
(ApplicationConstants.LOCATION_PROPERTY);
CustomerDB.CustomerRecord customer =
customerDb.lookup(firstName, lastName, location);
Console.WriteLine("OnMessage::QueryCommand with
FirstName=" + firstName + ";LastName=" +
lastName + ";Location=" + location);
reply = ConstructReplyMsg(customer);
} ...