Continuing my previous post where we saw how to de-queue a message from Oracle Stream Advanced queuing, this post will help us to understand the basic of how to enqueue a message into AQ.
Lets gets our hands-on by defining a payment process for our Newspaper Shop with Oracle SOA-BPEL 12C. We are going to expose a Http service for letting the customer to pay his invoice.
Having the same steps in mind, i made use of my same user that i have used in my previous post to create the needed queue-table and queue like below :
create type payment_type as OBJECT (paymentId varchar(25),amount number(6),
customerId number(6),paymentDate date); — define the structure of message
exec dbms_aqadm.CREATE_QUEUE_TABLE(queue_table => ‘payment_table_t’, queue_payload_type=>’payment_type’); — create the queue table
exec dbms_aqadm.create_queue(queue_name => ‘payment_table_q’, queue_table => ‘payment_table_t’); — create the needed queue with created queue table
exec dbms_aqadm.start_queue(‘payment_table_q’); –start the queue
Lets start with creating a SOA proj in jdeveloper.
- File –> New –> Project. In the dialog box shown, select SOA Project and press Ok.
- name the project in ‘receivePayment’ and press next. Select Empty composite and press the button Finish.
- In the SCA, right click on the component area (mid-lane), navigate to Insert –>BPEL Process.
- Name the bpel process and select the template as Synchronous BPEL process.
5. Now, lets define the parameters that we have to passed in the created XSD – receivePayment.xsd.
<element name=”paymentId” type=”string”/>
<element name=”amount” type=”nonNegativeInteger”/>
<element name=”customerId” type=”nonNegativeInteger”/>
<element name=”resultCode” type=”string”/>
<element name=”resultMessage” type=”string”/>
6. Lets create the AQ adapter in the right reference pane. Right click on the reference pane, Navigate to Insert –> AQ adapter. In the configuration wizard that is shown, enqueuePaymentAQ and click the button Next.
7. Select the connection for the shopKeeper schema and enter the JNDI name as ‘eis/AQ/newsPaper’ — the same one we created in the last post. Press next.
8. Lets define the interface later. So press next. In the operation type, select Enqueue. Click Next. Now, select the schema name(SHOP_KEEPER) and queue name(PAYMENT_TABLE_Q) as below:
9. Click next and pass on to Object Payload dialog box. Select the radio button for whole object PAYMENT_TYPE. And, click next and Finish.
10. now, wire the BPEL and AQ’s reference adapter. The SCA should be looking like below:
11. Now, double click on the BPEL process to edit it. Add a assign activity after the receive activity and name that as assignInput.
12. Add a invoke activity after the assign activity. name that as invoke_AQ. Wire the partner Link for the AQ adapter with the invoke. Edit invoke dialogue appears. Add the new input variable and save it as below :
13. Edit the assignInput to assign values to the invoke activity input variable. The copy rule should be like below :
Note : i have used the xpath function to convert the current-dateTime as below:
xp20:format-dateTime(xp20:current-dateTime(), ‘[D01]-[M01]-[Y0001] [H]:[m01]:[s01]’)
14. Now, add a assign activity after the invoke. Lets call that as assignOutput. Edit the copy rule to text the value ‘0’ to resultCode and ‘success’ to resultmessage. And press OK.
15. The Bpel process now should look like this:
16. Deploy the soa project and lets test it from the EM console. You should get the response as success.
Now, lets see if we can find the enqueued message in the AQ by using the query:
select * from AQ$payment_table_t ;
That is it. We can write a procedure (or forward the message to different queue) for the next action.
you can download the project i have created from git repo.
Have a great day.