Skip to content
Sean edited this page Dec 7, 2016 · 2 revisions

Welcome to svyDataBroadcaster

About this module

This module is intended to help synchronize Servoy applications when 3rd party applications have modified the underlying database contents.

When this happens, Servoy clients are not aware of the change and any data which has been cached will no longer reflect the true state of the database. To compensate for this, svyDataBroadcaster exposes a REST webservices endpoint allowing 3rd party applications to notify a Servoy Application Server when there has been a change.

Getting Started

To expose your applications to receive external data broadcast notifications, import this module to your app server or include this module in your .war file deployment. Your applications will automatically be enabled to receive external broadcasts.

The module also contains a scope dedicated to running/testing a REST client from within servoy application. It provides convenience methods to notify remote servers. By this approach, it is easy to test and program server-to-server notifications)

Invoking the external broadcast

The broadcast mechanism is invoked by submitting an HTTP PUT request to the service endpoint. The payload should carry the content listed below in the parameters section.

There are 2 approaches to updating your application server cache. Each approach has a REST endpoint and a required payload.

1. Flush Client Cache

This approach will trigger all clients to reload caches of specified table(s). This approach is thorough, but costly in terms of performance. Us this approach when you know that a table has been modified, but you don't have the record PKs

REST Endpoint:

<server-url>/servoy-service/rest_ws/svyDataBroadcaster/flush

i.e.

http://127.0.0.1:8080/servoy-service/rest_ws/svyDataBroadcaster/flush

Payload

The payload content consists of an object with the following properties:

  • serverName - the name of the DB server connection
  • tableName - the name of the table

Example: { "serverName":"example_data", "tableName":"example_data", }

2. Notify Data Change

This approach will trigger a data broadcast event to all clients. It is more nuanced and better-performing than flushing the cache. Use this approach when you know the PKs of records that were inserted, updated or deleted.

REST Endpoint:

<server-url>/servoy-service/rest_ws/svyDataBroadcaster/notify

i.e.

http://127.0.0.1:8080/servoy-service/rest_ws/svyDataBroadcaster/notify

Payload

The payload content consists of an object with the following properties:

  • serverName - the name of the DB server connection
  • tableName - the name of the table
  • pks - An array of PKs (composite keys are supported with nested arrays)
  • action - the SQL action (see constant for SQL_ACTIONS)

Example: { "serverName":"example_data", "tableName":"example_data", "pks":[1001,1002,1003], "action":2 }

Authentication

All REST endpoints support HTTP Basic Authentication out-of-the-box As such, any request can also include user name and password. For more information on this please read about Servoy's REST Plugin Authentication

REST Client Included

This module contains an additional scope svyDataBroadcasterClient which provides convenience methods for notifying remote servers. The module also contains a simple form which allows developers to quickly test their REST endpoints

To use this client run the svyDataBroadcaster module as a stand-alone solution, or include it as a module in your application.

Client API

The API provides two convenience methods to notify remote servers:

1. flushClientsCache

Use this method to flush the cache of a remote server

parameters:

  • @param {String} host

  • @param {String} serverName

  • @param {String} tableName

  • @param {String} [userName]

  • @param {String} [password]

  • @return {{success:Boolean, error:String, httpStatus:Number}}

2. notifyDataChange

Use this method to send discrete data broadcast messages to remote servers when record PKs are known

parameters:

  • @param {String} host

  • @param {String} serverName

  • @param {String} tableName

  • @param {Array<String|Number>|JSDataSet} pks

  • @param {Number} action

  • @param {String} [userName]

  • @param {String} [password]

  • @return {{success:Boolean, error:String, httpStatus:Number}}

Compatibility

This Module is compatible with Servoy versions 8x and 7x. It has not been tested with 6x, but should function w/o issue.

Dependencies

This module has the following dependencies:

License

This module is released under the MIT License