/*
 * Copyright (c) 2020, 2024 Oracle and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


-- SEND MESSAGE AS RAW BYTES
DECLARE
    id                 pls_integer;
    enqueue_options    DBMS_AQ.ENQUEUE_OPTIONS_T;
    message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
    message_handle     RAW(16);
    msg                sys.aq$_jms_bytes_message;
BEGIN
    msg := sys.aq$_jms_bytes_message.construct;
    id := msg.clear_body(-1);
    msg.write_bytes(id, UTL_RAW.CAST_TO_RAW('Hello raw bytes!'));
    msg.flush(id);
    DBMS_AQ.ENQUEUE(
            queue_name => 'FRANK.EXAMPLE_QUEUE_BYTES',
            enqueue_options => enqueue_options,
            message_properties => message_properties,
            payload => msg,
            msgid => message_handle);
    COMMIT;
END;

-- SEND TEXT MESSAGE
DECLARE
    enqueue_options    DBMS_AQ.ENQUEUE_OPTIONS_T;
    message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
    message_handle     RAW(16);
    msg                SYS.AQ$_JMS_TEXT_MESSAGE;
BEGIN
    msg := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
    msg.set_text('Hello from PLSQL !');
    DBMS_AQ.ENQUEUE(
            queue_name => 'FRANK.EXAMPLE_QUEUE_1',
            enqueue_options => enqueue_options,
            message_properties => message_properties,
            payload => msg,
            msgid => message_handle);
    COMMIT;
END;

-- SEND MAP MESSAGE
DECLARE
    id                 pls_integer;
    enqueue_options    DBMS_AQ.ENQUEUE_OPTIONS_T;
    message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
    message_handle     RAW(16);
    msg                SYS.AQ$_JMS_MAP_MESSAGE;
BEGIN
    msg := SYS.AQ$_JMS_MAP_MESSAGE.construct;
    id := msg.clear_body(-1);
    msg.set_string(id, 'head', 'Hello');
    msg.set_bytes(id, 'body', UTL_RAW.CAST_TO_RAW('this is map'));
    msg.set_string(id, 'tail', 'message!');
    msg.flush(id);
    DBMS_AQ.ENQUEUE(
            queue_name => 'FRANK.EXAMPLE_QUEUE_MAP',
            enqueue_options => enqueue_options,
            message_properties => message_properties,
            payload => msg,
            msgid => message_handle);
    COMMIT;
END;