/// <summary> /// This instance method enqueues multiple messages to a queue using the supplied enqueue options. /// </summary> /// <param name="messages"></param> /// <param name="options"></param> public Task <byte[][]> EnqueueArrayAsync(OracleAQMessage[] messages, OracleAQEnqueueOptions options, CancellationToken cancellationToken = default) { if (messages == null) { throw new ArgumentNullException(nameof(messages)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } // validate messages foreach (var message in messages) { message.ThrowIfInvalid(); } switch (MessageType) { case OracleAQMessageType.Raw: return(OracleAQQueueUtil.EnqueueRawArrayAsync(this, options, messages, cancellationToken)); case OracleAQMessageType.UDT: return(OracleAQQueueUtil.EnqueueUdtArrayAsync(this, options, messages, cancellationToken)); case OracleAQMessageType.Xml: return(OracleAQQueueUtil.EnqueueXmlArrayAsync(this, options, messages, cancellationToken)); default: throw new InvalidOperationException(); } }
/// <summary> /// Queues the given message and returns the new message ID. /// </summary> /// <param name="queue"></param> /// <param name="options"></param> /// <param name="message"></param> /// <param name="log"></param> /// <returns></returns> public static Task <byte[]> EnqueueXmlAsync( OracleAQQueue queue, OracleAQEnqueueOptions options, OracleAQMessage message, OracleLogger log, CancellationToken cancellationToken) { if (queue == null) { throw new ArgumentNullException(nameof(queue)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } if (log == null) { throw new ArgumentNullException(nameof(log)); } throw new NotImplementedException(); }
/// <summary> /// Queues the given message and returns the new message ID. /// </summary> /// <param name="queue"></param> /// <param name="options"></param> /// <param name="messages"></param> /// <returns></returns> public static Task <byte[][]> EnqueueUdtArrayAsync( OracleAQQueue queue, OracleAQEnqueueOptions options, OracleAQMessage[] messages, CancellationToken cancellationToken) { if (queue == null) { throw new ArgumentNullException(nameof(queue)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (messages == null) { throw new ArgumentNullException(nameof(messages)); } throw new NotImplementedException(); }
/// <summary> /// This instance method enqueues multiple messages to a queue using the supplied enqueue options. /// </summary> /// <param name="messages"></param> /// <param name="options"></param> public byte[][] EnqueueArray(OracleAQMessage[] messages, OracleAQEnqueueOptions options, CancellationToken cancellationToken = default) { return(EnqueueArrayAsync(messages, options, cancellationToken).Result); }
/// <summary> /// Queues the given message and returns the new message ID. /// </summary> /// <param name="queue"></param> /// <param name="options"></param> /// <param name="message"></param> /// <param name="log"></param> /// <returns></returns> public static async Task <byte[]> EnqueueUdtAsync( OracleAQQueue queue, OracleAQEnqueueOptions options, OracleAQMessage message, OracleLogger log, CancellationToken cancellationToken) { if (queue == null) { throw new ArgumentNullException(nameof(queue)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } if (log == null) { throw new ArgumentNullException(nameof(log)); } // fetch UDT type information var payloadType = await queue.GetPayloadTypeAsync(); if (payloadType == null) { throw new NullReferenceException("Unable to fetch message payload type."); } using (var cmd = queue.Connection.CreateCommand()) { cmd.BindByName = true; cmd.CommandType = CommandType.Text; cmd.CommandText = $@" DECLARE enqueue_options DBMS_AQ.enqueue_options_t; message_properties DBMS_AQ.message_properties_t; message_payload {payloadType}; message_id RAW(16); message_properties_xml XMLTYPE; message_payload_xml XMLTYPE; no_messages exception; PRAGMA EXCEPTION_INIT (no_messages, -25228); BEGIN enqueue_options.delivery_mode := {FormatDeliveryMode(options.DeliveryMode)}; enqueue_options.visibility := {FormatVisibility(options.Visibility)}; message_properties_xml := XMLTYPE(:message_properties); message_properties.priority := message_properties_xml.extract('/MESSAGE/PRIORITY/text()').getNumberVal(); -- message_properties.delay := message_properties_xml.extract('/MESSAGE/DELAY/text()').getNumberVal(); -- message_properties.expiration := message_properties_xml.extract('/MESSAGE/EXPIRATION/text()').getNumberVal(); message_properties.correlation := message_properties_xml.extract('/MESSAGE/CORRELATION/text()').getStringVal(); -- message_properties.exception_queue := message_properties_xml('/MESSAGE/EXCEPTION_QUEUE/text()').getStringVal(); -- message_properties.sender_id := message_properties_xml.extract('/MESSAGE/SENDER_ID/text()').getStringVal(); -- message_properties.user_property := message_properties_xml.extract('/MESSAGE/USER_PROPERTY/text()').getStringVal(); message_payload_xml := XMLTYPE(:message_payload); message_payload_xml.toObject(message_payload); DBMS_AQ.ENQUEUE( queue_name => :queue_name, enqueue_options => enqueue_options, message_properties => message_properties, payload => message_payload, msgid => message_id); :message_id := message_id; END;"; var queueNameParameter = cmd.CreateParameter(); queueNameParameter.ParameterName = ":queue_name"; queueNameParameter.OracleDbType = OracleDbType.Varchar2; queueNameParameter.Direction = ParameterDirection.Input; queueNameParameter.Value = queue.Name; cmd.Parameters.Add(queueNameParameter); var messagePropertiesXmlParameter = cmd.CreateParameter(); messagePropertiesXmlParameter.ParameterName = ":message_properties"; messagePropertiesXmlParameter.OracleDbType = OracleDbType.Varchar2; messagePropertiesXmlParameter.Direction = ParameterDirection.Input; messagePropertiesXmlParameter.Value = SerializeMessageProperties(message.Properties).ToString(); cmd.Parameters.Add(messagePropertiesXmlParameter); var messagePayloadXmlParameter = cmd.CreateParameter(); messagePayloadXmlParameter.ParameterName = ":message_payload"; messagePayloadXmlParameter.OracleDbType = OracleDbType.Varchar2; messagePayloadXmlParameter.Direction = ParameterDirection.Input; messagePayloadXmlParameter.Value = OracleObjectXmlTransferSerializer.Serialize((OracleObjectValue)message.Payload ?? payloadType.CreateNullValue()).ToString(); cmd.Parameters.Add(messagePayloadXmlParameter); var messageIdParameter = cmd.CreateParameter(); messageIdParameter.ParameterName = ":message_id"; messageIdParameter.Direction = ParameterDirection.Output; messageIdParameter.OracleDbType = OracleDbType.Raw; messageIdParameter.Size = 16; cmd.Parameters.Add(messageIdParameter); log.Debug(cmd.CommandText); await cmd.ExecuteNonQueryAsync(cancellationToken); // return new message id return(((OracleBinary)messageIdParameter.Value).Value); } }