3
votes

I've been studying marklogic replication alerting

http://docs.marklogic.com/guide/admin-api/flexrep#id_63603

I'm not clear on what specifically the alerting configuration in these examples are accomplishing. Could someone elaborate further? ( to be clear I understand the curl aspects)

Configuring Alerting

Use POST /manage/v2/databases/{id|name}/alert/configs to create the alerting configuration for the master database.

curl -X POST  --anyauth --user admin:admin
--header "Content-Type:application/json" \
-d '{
  "uri": "http://acme.com/alerting",
  "name": "qbfr",
  "description": "alerting rules for query-based flexrep",
  "trigger": [],
  "domain": [],
  "action": [],
  "option": []
   }' \

http://localhost:8002/manage/v2/databases/master/alert/configs

Use POST /manage/v2/databases/{id|name}/alert/actions to create the alert action and apply it to the alert configuration.

curl -X POST  --anyauth --user admin:admin
--header "Content-Type:application/json" \
-d '{
  "name": "log",
  "description": "QBFR log action",
  "module": "/log.xqy",
  "module-db": "master-modules",
  "module-root": "/",
  "option": []
   }' \

http://localhost:8002/manage/v2/databases/master/alert/actions ?uri=http://acme.com/alerting

Generally I would like an alert of data added to the replica from the master to execute a java api client process on the replica node. Can this be done with replication alerting?

Regards Conteh

3
I notice the simple trigger exampleconteh

3 Answers

3
votes

I haven't used replication alerting, so I can't comment on that. But in general, if you can run a server-side script, you can call out to a Java web server over HTTP. Use the xdmp:http libraries (here if you prefer server-side javascript). And, of course, you'll need your Java web server running and ready to accept HTTP requests. For that you could use Tomcat, Spring Boot, etc.

1
votes

The alerting configuration is just a way to associate a set of queries with a replication target, so that only documents that match one or more of those queries will replicate. There isn't actually any sort of alerting going on.

The flexrep configuration is associated with an alerting configuration URI, and then any targets that are hava a user configured on them will look for queries associated with that user within the alerting configuration.

By leveraging the alerting API, we avoided having to create a new API for managing queries specific to flexrep.

You only need to create the alerting configuration, create some action that doesn't need to do anything, and then create rules for each user associated with a flexrep target. You don't need to create alerting triggers, or add alerting to your CPF pipeline.

Does that clear things up for you?

0
votes

if the only purpose of the java app is to run marklogic client code, which in turn just calls back to marklogic to run code that otherwise doesn't need java then you could implement that logic instead in xquery or javascript in the server natively and avoid the need for a java server / process -- run faster with less administration.

if you want java explicitly there are many lightweight http server frameworks such as nginx which can launch a java process. if this is expected to be frequent i do not recommend starting a new jvm every time --- java has a heavy startup cost. if you are running in a managed cloud environment like aws or azure you can make use of their 'api gateway' products to run java code as a result of an http call without managing an 'server'. a crude but effective possibility is simply writing a file the have a cron task periodically check it and run java .. this is only effective if you can tolerate (or desire) minute+ delay between the trigger and launch of java. (note; the aws managed cluster feature uses this technique for a few occasional tasks )

faster detection and startup may be achieved by an inotify/fsnotify daemon watching the directly -- depending on the os and fikesystem this can trigger in as little as sub millisecond (then take 100+ ms to start java) compromise - use the java based file watcher ---

easiest and likely 'best' answer is the first one by sam -- run a long-standing java app listening for http requests. this can be done efficiently by choosing one of many 'lite' http server libraries including that built in to java (about 5 lines of java with no dependencies). could be run in docker to share with other services if you don't want to run on the same server as marklogic.