getMessage

getMessage(msg:     JadeGenericMessage input;
           options: String): Boolean;

The getMessage method of the JadeGenericQueue class retrieves a message from the queue and copies its contents into the message object passed into the method and specified by the msg parameter. If there are no messages in the queue, the method returns false.

The JadeGenericQueue instance that created the msg message object (using the createMessage method) need not be the same instance that retrieves the message with the getMessage method, but both JadeGenericQueue instances must use the same transport.

If the msg object has previously been used to put an object in a queue by using the putMessage method or to retrieve a message from a queue by using the getMessage or getMessageByCorrelationID method, it must be initialized by using the initializeForGet method defined in the JadeGenericMessage class.

If the options parameter is a null string, transport-specific default actions are taken. Options passed to this method override any specified in the defaultPutMessageOptions property.

Components that can be included in the options parameter string for the JadeMQ transport are listed in the following table. (These options are ignored for the WebSphere MQ transport.)

Component Result
NoWait The method returns immediately if no message is available
Timeout=milliseconds The method waits for the specified number of milliseconds for a message to arrive
Timeout=0 The method waits indefinitely (the default implied option)

The queue must be opened by the openQueue method defined in the JadeMessagingFactory class, with Usage=Get or Usage=All included in the options parameter.

The following example shows the use of the getMessage method to retrieve a message from a queue.

vars
    factory : JadeMessagingFactory;
    msg : JadeGenericMessage;
    queue : JadeGenericQueue;
begin
    create factory transient;
    queue := factory.openQueue("JadeMQ://localnode/TestQ", "Usage=All");
    msg := queue.createMessage(false);
    queue.getMessage(msg, "Timeout=5000");
    write msg.body.String;
epilog
    delete factory;
    delete msg;
    delete queue;
end;