Today I was configuring a message driven bean to listen to an AQ queue. The tutorials and examples I found had me create the queue like this:

dbms_aqadm.create_queue_table( queue_table=>'MY_QUEUE_TABLE'
                             , queue_payload_type=&gt;<strong>'SYS.AQ$_JMS_TEXT_MESSAGE'</strong>
                             , multiple_consumers=&gt;false);

With this queue type, I managed to configure the Message Driven Bean successfully on an OC4J 10.1.2 without needing to use the JCA AQ Adapter, i.e. with just plain JMS. I also wrote a Java class to enqueue a test JMS message on this queue. But then, I needed to write PL/SQL code to put a message on this queue as well. Not being very fluent in PL/SQL programming, I tried googling for an example, but all the examples I found used code like this:

create or replace procedure testmessage AS
&nbsp; msg SYS.AQ$_JMS_TEXT_MESSAGE;
&nbsp; queue_options DBMS_AQ.ENQUEUE_OPTIONS_T;
&nbsp; msg_props DBMS_AQ.MESSAGE_PROPERTIES_T;
&nbsp; msg_id RAW(16);
begin
&nbsp; <strong>msg := SYS.AQ$_JMS_TEXT_MESSAGE.CONSTRUCT();<br /></strong>&nbsp; msg.set_text('Hello World from PL/SQL');
&nbsp; DBMS_AQ.ENQUEUE( queue_name =&gt; 'MyQueue'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , enqueue_options =&gt; queue_options
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , message_properties =&gt; msg_props
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , payload =&gt; msg
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , msgid =&gt; msg_id);
end;

Unfortunately, this code does not compile on the Oracle XE database that I was using, resulting in a "PLS-00302: component ‘CONSTRUCT’ must be declared" error. Further examination taught me that the JMS types on the XE database are "crippled’ because there is no JVM present. The advice I repeatedly came across was to use a queue with an ADT payload rather than a JMS type payload, at the cost of more complex dequeuing logic in the middle tier.

....

But I knew the JMS-type queue was working fine when enqueuing from Java, so I kept trying until I came up with some PL/SQL that enqueued the exact same messages as the ones I created from Java. Maybe (hopefully)  this is not the easiest way to do it but I found several (unanswered) forum posts from people struggling with the very same problem, so at least this is _a_ solution. I welcome suggestions and improvements!

create or replace procedure testmessage AS
&nbsp; msg SYS.AQ$_JMS_TEXT_MESSAGE;
&nbsp; msg_hdr SYS.AQ$_JMS_HEADER;
&nbsp; msg_agent SYS.AQ$_AGENT;
&nbsp; msg_proparray SYS.AQ$_JMS_USERPROPARRAY;
&nbsp; msg_property SYS.AQ$_JMS_USERPROPERTY;
&nbsp; queue_options DBMS_AQ.ENQUEUE_OPTIONS_T;
&nbsp; msg_props DBMS_AQ.MESSAGE_PROPERTIES_T;
&nbsp; msg_id RAW(16);
&nbsp; dummy VARCHAR2(4000);
begin
&nbsp; msg_agent := SYS.AQ$_AGENT(' ', null, 0);
&nbsp; msg_proparray := SYS.AQ$_JMS_USERPROPARRAY();
&nbsp; msg_proparray.EXTEND(1);
&nbsp; msg_property := SYS.AQ$_JMS_USERPROPERTY('JMS_OracleDeliveryMode', 100, '2', NULL, 27);
&nbsp; msg_proparray(1) := msg_property;

&nbsp; msg_hdr := SYS.AQ$_JMS_HEADER(msg_agent,null,'&lt;USERNAME&gt;',null,null,null,msg_proparray);
&nbsp; msg := SYS.AQ$_JMS_TEXT_MESSAGE(msg_hdr,null,null,null);
&nbsp; msg.text_vc := 'Hello from PL/SQL on XE';
&nbsp; msg.text_len := length(msg.text_vc);
&nbsp; DBMS_AQ.ENQUEUE( queue_name =&gt; 'MyQueue'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , enqueue_options =&gt; queue_options
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , message_properties =&gt; msg_props
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , payload =&gt; msg
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , msgid =&gt; msg_id);
end;
&nbsp;