MarkLogic Server 11.0 Product Documentation
flexrep.targetCreate

flexrep.targetCreate(
   cfg as element(flexrep.configuration),
   name as String,
   urls as String[],
   retry-seconds-min as Number?,
   retry-seconds-max as Number?,
   documents-per-batch as Number?,
   enabled as Boolean?,
   http-options as element(flexrep.httpOptions)?,
   replicate-cpf as Boolean?,
   filter-module as String?,
   filter-options as element(flexrep.filterOptions)?,
   [user-id as (Number|String)?],
   [immediate-push as Boolean]
) as element(flexrep.configuration)

Summary

This function creates a new target and add it to the specified configuration. A random ID is chosen for the target. You must subsequently use flexrep.configurationInsert to write the modified configuration into the database.

Parameters
cfg The configuration to which to add the target.
name The name of the target.
urls The URLs to be used to push replicated content to, with the load spread across them if there is more than one. If none are specified, the target is expected to do a pull.
retry-seconds-min The minimum time to wait before scheduling a push retry.
retry-seconds-max The maximum time to wait before scheduling a push retry.
documents-per-batch The number of documents to attempt to replicate from a single invocation of the scheduled replication task.
enabled Specifies whether or not this target is enabled.
http-options HTTP options to use when connecting to the target. Specify the options as an XML element named http-options in the "flexrep" namespace. The options element can contain any of the options from the xdmp:http-get function. When including an option from another function, use use the namespace appropriate to that function in the option child element. For more details, see the Examples.
replicate-cpf Determines whether to replicate CPF. Set to true to replicate CPF. Otherwise set to false. In most circumstances, you will not want to replicate CPF.
filter-module A main module to filter replication attempts.
filter-options Options to apply when invoking an outbound filter module. Specify the options as an XML element named filter-options in the "flexrep" namespace. The options element can contain any of the options from xdmp:invoke. The option child elements from xdmp:invoke must be in the "xdmp:eval" namespace.
user-id The user ID if this is a query-based target.
immediate-push Specifies whether to push to the query-based target immediately. The default is true.

Example

const flexrep = require('/MarkLogic/flexrep');

  declareUpdate();
  //Obtain the ID of the replicated CPF domain from the Triggers database.
    const domain = xdmp.eval(
    'const dom = require("/MarkLogic/cpf/domains");' +
      'fn.data(dom.get("Default Master").xpath("//dom:domain-id"));',
       null,
         {
          'database' : xdmp.database('Triggers')
         });

  // Obtain the replication configuration.
  let config = flexrep.configurationGet(domain, true); 

  // Specify the HTTP options for the replication target.
  let httpOptions = fn.head(xdmp.unquote('<flexrep:http-options xmlns:flexrep="http://marklogic.com/xdmp/flexible-replication">' +
      '<http:authentication xmlns:http="xdmp:http">' +
        '<http:username>admin</http:username>' +
        '<http:password>admin</http:password>' +
      '</http:authentication>' +
      '<http:client-cert xmlns:http="xdmp:http"/>' +
      '<http:client-key xmlns:http="xdmp:http"/>' +
      '<http:pass-phrase xmlns:http="xdmp:http"/>' +
    '</flexrep:http-options>'
    )).root;

  // Create the replication target.
  let cfg = flexrep.targetCreate(
    config,
    'Replica',
    'http://localhost:8011/',
    60,
    300,
    10,
    true,
    httpOptions,
    false,
    null,
    null );

  // Insert the changes to the replication configuration.
  flexrep.configurationInsert(cfg); 
 
  // Creates a replication target, named "Replica." 
   
Powered by MarkLogic Server | Terms of Use | Privacy Policy