Broker 10.5 | webMethods Broker Documentation | webMethods Broker Messaging Programmer's Guide | Coding Messaging Client Applications | C# Messaging Clients | Application Code | Implementing Messaging on a Second Thread
 
Implementing Messaging on a Second Thread
In addition to receiving customer inquiry messages on an asynchronous messaging thread, the server application can receive administrator shutdown commands on the main thread.
The administrator shutdown command is sent from an admin client to the server. To control which clients can send the shutdown command to the server, you can create a separate client group that has permission to send messages to the admin Queue. You use the JMSAdmin command-line tool to create this group at server application and admin client startup.

ISession adminSession;
IMessageConsumer adminReceiver;
IDestination adminDestination;
...
adminSession = conn.CreateSession(false, AcknowledgeMode.Auto);
adminReceiver = adminSession.CreateConsumer(adminDestination);
A loop in serverRun() controls server operation and shutdown, as shown below. Message reception for the shutdown command occurs via a synchronous receive() method, unlike the asynchronous message listener that receives customer inquiries on the other messaging thread.
void ServerRun()
{
bool running = true;
while (running) {
try {
IMessage msg = adminReceiver.Receive();
String command = (msg.GetStringProperty
(ApplicationConstants.ADMIN_COMMAND_PROPERTY);
Console.WriteLine("Received a command: " + command);
if (command == null) {
continue; }
 
if (command.Equals(ApplicationConstants.ADMIN_COMMAND_SHUTDOWN,
StringComparison.InvariantCultureIgnoreCase)) {
Console.WriteLine("Shutting down");
conn.Stop();
running = false; }
} ...
}