Examples
Generic engine_send HTTP service
This example is the same as the default configuration supplied with Apama.
YAML dynamic chain:
dynamicChains:
HTTPServerChain:
- apama.eventMap
- mapperCodec:
"*":
towardsHost:
mapFrom:
- metadata.sag.type: payload.type
- metadata.sag.channel: payload.channel
- payload: payload.data
- jsonCodec
- stringCodec
- HTTPServerTransport:
authentication:
authenticationType: none
allowedUsersFile: ${PARENT_DIR}/userfile.txt
automaticResponses: true
allowedMethods: [PUT]
EPL:
event Temperature
{
integer sensorId;
string sensorName;
float temperature;
dictionary<string,any> extra;
}
monitor.subscribe("myChannel");
on all Temperature() as e {
// ...
}
Curl example:
curl -X PUT http://localhost:8080/ -d '{"type":"Temperature",
"channel":"myChannel", data:{"sensorId":666, "sensorName":"FooBar",
"temperature":3.14",{"A":"alpha"}} }' -H "Content-Type:application/json"
Event type and channel information is specified in headers
YAML dynamic chain:
dynamicChains:
HTTPServerChain:
- apama.eventMap
- mapperCodec:
"*":
towardsHost:
mapFrom:
- metadata.sag.type : metadata.http.headers.x-apamaeventtype
- metadata.sag.channel : metadata.http.headers.x-apamachannel
- jsonCodec
- stringCodec
- HTTPServerTransport:
authenticationType: none
allowedUsersFile: ${PARENT_DIR}/userfile.txt
automaticResponses: true
allowedMethods: [PUT]
EPL:
event Temperature
{
integer sensorId;
string sensorName;
float temperature;
dictionary<string,any> extra;
}
monitor.subscribe("myChannel");
on all Temperature() as e {
// ...
}
Curl example:
curl -X PUT -H "X-ApamaEventType:Temperature" -H "X-ApamaChannel:myChannel"
http://localhost:8080/ -d '{"sensorId":666, "sensorName":"FooBar",
"temperature":3.14",{"A":"alpha"} }' -H "Content-Type:application/json"
Event type and channel information is specified in the query string
YAML dynamic chain:
dynamicChains:
HTTPServerChain:
- apama.eventMap
- mapperCodec:
"*":
towardsHost:
mapFrom:
- metadata.sag.type : metadata.http.queryString.eventType
- metadata.sag.channel : metadata.http.queryString.channel
- jsonCodec
- stringCodec
- HTTPServerTransport:
authenticationType: none
allowedUsersFile: ${PARENT_DIR}/userfile.txt
automaticResponses: true
allowedMethods: [PUT]
EPL events:
event Temperature
{
integer sensorId;
string sensorName;
float temperature;
dictionary<string,any> extra;
}
monitor.subscribe("myChannel");
on all Temperature() as e {
// ...
}
Curl example:
curl -X PUT 'http://host:port/submit?eventType=Temperature&channel=myChannel'
-d '{"sensorId":666, "sensorName":"FooBar", "temperature":3.14",{"A":"alpha"} }'
Event types are tied to the method and path and the channel is defaulted
YAML dynamic chain:
dynamicChains:
HTTPServerChain:
- apama.eventMap
- mapperCodec:
KickEvent:
towardsHost:
- metadata.sag.channel: kickEvents
DocumentSubmissionEvent:
towardsHost:
mapFrom:
- payload.data: payload
defaultValue:
- metadata.sag.channel: submissionEvents
DocumentUpdateEvent:
towardsHost:
mapFrom:
- payload.data: payload
defaultValue:
- metadata.sag.channel: updateEvents
- classifierCodec:
rules:
- KickEvent:
- metadata.http.method: GET
- metadata.http.path: /kick
- DocumentSubmissionEvent:
- metadata.http.method: PUT
- metadata.http.path: /submit
- DocumentUpdateEvent:
- metadata.http.method: PUT
- metadata.http.path: /update
- stringCodec
- HTTPServerTransport:
authenticationType: none
allowedUsersFile: ${PARENT_DIR}/userfile.txt
automaticResponses: true
allowedMethods: [PUT, GET]
EPL events:
event KickEvent { }
event DocumentSubmissionEvent { string data; }
event DocumentUpdateEvent { string data; }
Delivering Apama event strings
This example is using the string form of the event native to Apama. You should only use this example if you have a system that encodes events in that format.
YAML dynamic chain:
dynamicChains:
HTTPServerChain:
- apama.eventString
- mapperCodec:
"*":
towardsHost:
mapFrom:
- metadata.sag.channel: metadata.http.path
- stringCodec
- HTTPServerTransport:
authenticationType: none
allowedUsersFile: ${PARENT_DIR}/userfile.txt
automaticResponses: true
allowedMethods: [PUT]
EPL:
monitor.subscribe("/channel/ChannelName");
on all Temperature() as e { ... }
Curl example:
curl -X PUT http://host:port/channel/ChannelName -d 'Temperature(10, "Baz",
6.022e23)'
EPL-controlled responses
This example generates responses to the HTTP requests in EPL. Requests should be JSON objects containing
objectId and
requestType. Responses are arbitrary JSON objects. See also
Handling responses in EPL.
YAML dynamic chain:
dynamicChains:
HTTPServerChain:
- apama.eventMap:
defaultChannel: requests
defaultEventType: HTTPRequest
- mapperCodec:
"*":
towardsHost:
mapFrom:
- payload.requestId: metadata.requestId
defaultValue:
- payload.channel: "@{httpServer.responseChannel}"
towardsTransport:
mapFrom:
- metadata.requestId: payload.requestId
- payload: payload.responseData
defaultValue:
- metadata.http.statusCode: 200
- jsonCodec
- stringCodec
- HTTPServerTransport:
automaticResponses: false
allowedMethods: [ PUT ]
EPL:
monitor.subscribe("requests");
on all HTTPRequest() as r {
send HTTPResponse(r.requestId, getResponseData(r.requestType, r.objectId))
to r.channel;
}
EPL events:
event HTTPRequest {
integer requestId;
integer objectId;
string requestType;
string channel;
}
event HTTPResponse {
integer requestId;
any responseData;
}