WebSocket together with DB Change Notification in ADF for immediate data refresh in browser (complete sample).


To achieve our goal we need somehow to know when changes in DB happen. Once we know when, need to notify browser session in order it could be refreshed. This time we'll exploit two Java offerings:
Lets do simple PoC with EMPLOYEES table from HR schema. Just display its contents and immediately refresh if changes happen in this table.
Make sure you have access to any Oracle DB (recommended >= 11.1 - more DCN features available) HR schema.

Recent action has been generated web content folder with necessary belongings. 
Note that method processMessageFromClient will not be used by fact in this sample, because it is not necessary to fullfill our requirement. But we just add a stub of it to be able to utilize it later if necessary. We have full WebSocket service structure defined already. It can be deployed although will not process anything benefiting our needs.

Notice WebSocket service URL marked with green rectangle. You need to check if its the same in your enviroment. Target URL is displayed right after running service in integrated server:

At this moment were done with basic WebSocket connectivity implementation. We can run either ViewController and WebSocket project and try to enable and disable WebSocket connection. Check how it works:

grant change notification to hr;

In the Integrated server and browser logs can see notification cycle logged:


Note: for cleaning DB registrations can use app described in my other post How to select all JDBC Database Change Notification Registrations and clean them?

Demo application can be downloaded here
More info about Database Change Notifications
More info about WebSocket

JDeveloper version

Labels: , , ,