I had a requirement when I had to enter / deactivate UDT messages in a queue. This post was really helpful. He has almost everything, but the creation of the "Oracle Custom Type" is missing. I thought it was worth adding this code here so that the solution is complete.
In EnQueue / DeQueue in Oracle:
A user with the role "AQ_ADMINISTRATOR_ROLE" must be created. The example below creates "AQUSER" with this role.
PL Sql to EnQueue: DECLARE queue_options DBMS_AQ.ENQUEUE_OPTIONS_T; message_properties DBMS_AQ.MESSAGE_PROPERTIES_T; message_id RAW(16); my_message AQUSER.USER_DEFINED_TYPE; BEGIN my_message := AQUSER.USER_DEFINED_TYPE('XXX','YYY','ZZZ'); DBMS_AQ.ENQUEUE( queue_name => 'AQUSER.QUEUE_NAME', enqueue_options => queue_options, message_properties => message_properties, payload => my_message, msgid => message_id); COMMIT; END; / PL SQL to DeQueue DECLARE queue_options DBMS_AQ.DEQUEUE_OPTIONS_T; message_properties DBMS_AQ.MESSAGE_PROPERTIES_T; message_id RAW(2000); my_message AQUSER.USER_DEFINED_TYPE; BEGIN DBMS_AQ.DEQUEUE( queue_name => 'AQUSER.QUEUE_NAME', dequeue_options => queue_options, message_properties => message_properties, payload => my_message, msgid => message_id ); COMMIT; END; / ------------------------------------------------------------------------------------------- To create a Oracle Custom Type, you can use the following code: public class CustomMessageType : IOracleCustomType, INullable { [OracleObjectMappingAttribute("XXXXX")] public string XXXXX { get; set; } [OracleObjectMappingAttribute("YYYYY")] public string YYYYY { get; set; } [OracleObjectMappingAttribute("ZZZZZ")] public string ZZZZZ { get; set; } public void FromCustomObject(Oracle.DataAccess.Client.OracleConnection con, IntPtr pUdt) { if (!string.IsNullOrEmpty(XXXXX)) { OracleUdt.SetValue(con, pUdt, "XXXXX", XXXXX); } if (!string.IsNullOrEmpty(YYYYY)) { OracleUdt.SetValue(con, pUdt, "YYYYY", YYYYY); } if (!string.IsNullOrEmpty(ZZZZZ)) { OracleUdt.SetValue(con, pUdt, "ZZZZZ", ZZZZZ); } } public void ToCustomObject(Oracle.DataAccess.Client.OracleConnection con, IntPtr pUdt) { XXXXX = (string)OracleUdt.GetValue(con, pUdt, "XXXXX"); YYYYY = (string)OracleUdt.GetValue(con, pUdt, "YYYYY"); ZZZZZ = (string)OracleUdt.GetValue(con, pUdt, "ZZZZZ"); } public bool IsNull { get; set; } } [OracleCustomTypeMappingAttribute("SCHEMA.CUSTOM_TYPE")] public class QueueMessageTypeFactory : IOracleCustomTypeFactory { public IOracleCustomType CreateObject() { return new CustomMessageType(); } }
Vishal a
source share