Publishing from Server Script
You can publish event data from Siebel CRM to Apache Kafka using server scripts. This
section lists simplified examples to demonstrate how to send event data to Apache Kafka
using a server script and the impact of the SingleRecordAsJSONObject
property.
You use the setProperty
method to publish a topic to specific Kafka
partitions. The following example is a section of the server script that demonstrates
how to publish event data to specific partitions:
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
var nReturn = ContinueOperation;
var oBS;
var ch1;
var outPS;
var conPS;
var accPS;
switch (MethodName) {
case "PublishContact":
ch1 = TheApplication().NewPropertySet();
outPS = TheApplication().NewPropertySet();
conPS = TheApplication().NewPropertySet();
accPS = TheApplication().NewPropertySet();
accPS.SetProperty("topic","AccountData");
accPS.SetProperty("partitions", "0,1,3");
ch1.SetType("Contact");
ch1.SetProperty("First Name", "Anil");
ch1.SetProperty("Last Name", "Kumar")
conPS.AddChild(ch1);
conPS.SetProperty("Account Name","SF");
conPS.SetType("Account");
accPS.AddChild(conPS);
oBS = TheApplication().GetService("Event Handler");
oBS.InvokeMethod("SendEvent", accPS, outPS);
nReturn = CancelOperation;
break;
}
return nReturn;
}
In the example above, the Partitions property for AccountData is set to the values 0, 1, and 3. Hence, the JSON message generated for AccountData using this server script will be posted to these partitions.
The following example demonstrates how a JSON payload is posted to Kafka based on the
value of the SingleRecordAsJSONObject
property:
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
var nReturn = CancelOperation;
var oBS;
var topPS;
var outPS;
var conPS;
var accPS;
var fieldList = ["First Name", "Last Name"];
switch (MethodName) {
case "PublishContact":
topPS = TheApplication().NewPropertySet();
outPS = TheApplication().NewPropertySet();
conPS = TheApplication().NewPropertySet();
accPS = TheApplication().NewPropertySet();
topPS.SetProperty("topic","customcontactevent");
accPS.SetType("Account");
accPS.SetProperty("Name",”NoAccount123");
accPS.SetProperty("SingleRecordAsJSONObject",”true");
conPS.SetType("Contact");
for (var j=0; j<fieldList.length; j++)
{
conPS.SetProperty(fieldList[j], "NoName");
}
accPS.AddChild(conPS);
topPS.AddChild(accPS);
oBS = TheApplication().GetService("Event Handler");
oBS.InvokeMethod("SendEvent", topPS, outPS);
break;
}
return nReturn;
}
}
Based on the configuration in the above example and assuming that
SIEBEL_EVENT_PUBSUB_PAYLOAD_STRUCT
is set to 2
,
the business objects are posted as follows:
{
"Account": {
"Name": "NoAccount123",
"Contact": [
{
"First Name": "NoName",
"Last Name": "NoName"
}
]
}
}
- A single data record of “Contact” will be posted as an array as the
SingleRecordAsJSONObject
property is not set. - A single data record of “Account” will be posted as a JSON object as the
SingleRecordAsJSONObject
property is set totrue
.