3

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

1
  • I notice the simple trigger example
    – conteh
    Apr 12, 2016 at 12:38

3 Answers 3

3

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.

3
  • Thanks sam. Yeah I would like to have a Java web server running that would use the marklogic java api client to do some tasks as a results of the replication alert if that is feasible. It would be cleaner if the process was launched as a result of an alert that the data had been replicated.
    – conteh
    Apr 11, 2016 at 16:32
  • You could always have a trigger on destination server that calls out to the local java service. Apr 12, 2016 at 10:24
  • I notice the simple trigger example docs.marklogic.com/guide/app-dev/triggers#id_66092 is very similar in that the log.xqy module trgr:trigger-module(xdmp:database("test"), "/modules/", "log.xqy") is executed. Perhaps then the replication alert is essentially like a trigger.
    – conteh
    Apr 12, 2016 at 12:42
1

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?

2
  • If you don't wish to have queries that filter what is actually replicated, there is no need to configure anything for alerting. Apr 21, 2016 at 0:33
  • Thanks @WayneFeick,,, makes sense
    – conteh
    Apr 21, 2016 at 15:50
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.