CREATE OR REPLACE PROCEDURE "&1".MESSAGE_ENQUEUE_TO_SOLACE(TRANSFER IN NUMBER) IS

  ENQUEUE_OPTIONS    DBMS_AQ.ENQUEUE_OPTIONS_T;
  MESSAGE_PROPERTIES DBMS_AQ.MESSAGE_PROPERTIES_T;
  MESSAGE_HANDLE     RAW(16);
  MESSAGE            SYS.AQ$_JMS_TEXT_MESSAGE;
  MESSAGE_TEXT       CLOB;
  L_COUNTRY          VARCHAR2(3);
  L_PLANT            VARCHAR2(6);
  L_CUSTOMER_CRM     VARCHAR2(18);
  L_SOLACE_TOPIC_OUT VARCHAR2(100);

BEGIN

  SELECT ERP.COUNTRY, ERP.BUSINESSUNIT, ERP.CRMCUSTOMERNUMBER
    INTO L_COUNTRY, L_PLANT, L_CUSTOMER_CRM
    FROM "&3".ERP_I_CUSTOMER ERP
   WHERE ERP.TRANSFER_ID = TRANSFER
	 AND ERP.SEND_RESPONSE = 'N'
     AND ROWNUM = 1;
 
  IF L_COUNTRY IS NULL THEN
    RETURN;
  END IF;
	 
  SELECT ST.SOLACE_TOPIC_OUT
    INTO L_SOLACE_TOPIC_OUT
    FROM "&1".SOLACE_TOPIC ST
   WHERE ST.PROCESSING_NUMBER = 1;

  MESSAGE_TEXT := '{ "countryCode": "' || L_COUNTRY ||
                  '", plantId": "' || L_PLANT || 
                  '", elisId": "' || L_CUSTOMER_CRM || '"}';  
  MESSAGE      := SYS.AQ$_JMS_TEXT_MESSAGE.CONSTRUCT;
  MESSAGE.SET_TEXT(MESSAGE_TEXT);
  MESSAGE.SET_STRING_PROPERTY('solace_topic_out', L_SOLACE_TOPIC_OUT || '/' || L_COUNTRY || '/' || L_PLANT || '/' || L_CUSTOMER_CRM);
  
  DBMS_OUTPUT.PUT_LINE(MESSAGE_TEXT);
  DBMS_AQ.ENQUEUE(QUEUE_NAME         => 'SEND_TO_SOLACE_QUEUE',
                  ENQUEUE_OPTIONS    => ENQUEUE_OPTIONS,
                  MESSAGE_PROPERTIES => MESSAGE_PROPERTIES,
                  PAYLOAD            => MESSAGE,
                  MSGID              => MESSAGE_HANDLE);

END MESSAGE_ENQUEUE_TO_SOLACE;
/
exit;