Page 1 of 1

AQ how to register an agent from devart

Posted: Mon 14 Sep 2009 10:06
by Kurt_Jegge
Hello

Is there an example how tho register an agent
in an oracle raw queue which would be for multipleConsumers?

I used the ODAC demo but there is a non multipleConsumer
sample.

code:

Oracle 9i testcode:

queuetable

BEGIN
DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'trafdev.print_queue_table',
queue_payload_type => 'RAW',
multiple_consumers => TRUE);
END;
/

the so created user_data field of the queuetable is a blob

enqueuing

declare
r_enqueue_options DBMS_AQ.ENQUEUE_OPTIONS_T;
r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
v_message_handle RAW(16);
o_payload RAW(200);
begin
o_payload := SYS.UTL_RAW.cast_to_raw ('Hello');
SYS.DBMS_AQ.ENQUEUE('print_queue', r_enqueue_options,
r_message_properties, o_payload, v_message_handle);
COMMIT;
end;

I couldn't find a working example how to create and set
TQueueAgents and TQueueAgent with multiple_consumers = YES,
so I used the OracleQueue properties which I set before.

procedure TForm1.Button1Click(Sender: TObject);
var
Agents: TQueueAgents;
Agent: TQueueAgent;
StringPayload : String;
MsgId: String;
begin
Agents := oq.EnqueueMessageProperties.RecipientList;
try
Agent := oq.EnqueueMessageProperties.RecipientList.Items[0];
try
oq.Listen(Agents, Agent, -1);
MsgId := oq.Dequeue(StringPayload);
memo1.Lines.Add('DEQUEUE: MsgId: ' + MsgId + ' Payload: ' +
StringPayload);
finally
Agent := nil;
end;
finally
Agents := nil;
end;
end;

Dequeuing works MsgId is OK, the queue is emptied but in
Payload I get '?????'

I have to admit that I am starting with Oracle Queuing.
Therefore any help would be much appreciated.

Best regards.

Kurt

Posted: Tue 15 Sep 2009 09:39
by Plash
1. The Listen method has input agent list and one output agent.
You should set Name for the input agent:

Code: Select all

  InAgents := TQueueAgents.Create;
  try
    InAgent := Agents.Add;
    InAgent.Name := 'MyName';
    InAgent.Address := 'QU_ODAC_RAW';

    OutAgent := TQueueAgent.Create;
    try
      QueueRaw2.Listen(InAgents, OutAgent, StrToInt(edWaitTimeout.Text));
      ShowMessage('A message is available in queue ' + OutAgent.Address);
    finally
      Agent.Free;
    end;
  finally
    Agents.Free;
  end;
2. Please try to use the overload of Dequeue that returns the payload as array of bytes. Tell me what values will contain this array.
Try to enqueue and dequeue a payload using the ODAC demo. Can you get normal text in the demo?