Karthick
Karthick

Reputation: 256

How to execute a query in eval.xqy file with app-server id

I need to run query with importing modules from pod.

Without importing modules if I run simple query with Database Id using below, it is working.

let $queryParam := fn:concat("?query=",xdmp:url-encode($query),"&eval=",$dataBaseId,":123")
let $url := fn:concat($hostcqport,"/eval.xqy",$queryParam)

let $response := xdmp:http-post($url, $options)[2]

If I have import modules statements then it is throwing Error(File Not Found).

So I tried getting the app-server id and tried passing that instead of database-id as below,

let $queryParam := fn:concat("?query=",xdmp:url-encode($query),"&eval=",$serverId,":123")
let $url := fn:concat($hostcqport,"/eval.xqy",$queryParam)

let $response := xdmp:http-post($url, $options)[2]

How to pass the server-id to make the query executing against particular app-server.

Upvotes: 1

Views: 308

Answers (1)

Is this MarkLogic 8 or earlier (I ask because rewrite options on 8 allow for dynamic switching of module databases before execution (among lots of other amazing goodies). This may be what you want because you can look at the query parameters at this point and build logic into the rewite rules.

Otherwise, Can you explain in more detail what you are trying to accomplish in the end. By the time your code ran, it was already executed in the context of a particular App server - so asking to execute against a another app server by analysing the query parameters is a bit too late (because you are already using the app server).

[edit] The following is in response to the comments since provided. This is a messy response because the actual ticket and comments are still not a completely clear picture. But if you stitch them together, then a problem statement does now exist for which I can respond.

The original author of the question confirmed via comments that they are "trying to hit an app server on a different node than the one that you actually posted to"

OK.. This is the response to that clarification: That is not possible. Your request is already being processed by a thread on the node that you hit with your http request. Marklogic is a cluster, but it does not share threads (or anything else for that matter). Choices are:

  • a redirect to the proper node
  • possibly use the current node to make the request on your behalf.
  • But that ties up the first thread and the thread on the other node and has the HTTP communication overhead - and you need to have an app server listening for this purpose.
  • If this is a fire-and-forget type of situation, then you can hit any node and save the data/request in a document in the DB using a URI naming convention that indicates what app server it is for, and by way of insert triggers (with a URI-prefix for their server id), pick up the request from the DB and process it.

Upvotes: 1

Related Questions