Apama 10.3 | Apama Documentation | Connecting Apama Applications to External Components | Standard Connectivity Plug-ins | The HTTP Server Transport Connectivity Plug-in | Mapping events between EPL and HTTP server requests | Examples
 
Examples
Generic engine_send HTTP service
This example is the same as the default configuration supplied with Apama.
YAML dynamic chain:
dynamicChains:
httpServer:
- apama.eventMap
- mapperCodec:
"*":
towardsHost:
mapFrom:
- metadata.sag.type: payload.type
- metadata.sag.channel: payload.channel
- payload: payload.data
- jsonCodec
- stringCodec
- httpServer:
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:
httpServer:
- apama.eventMap
- mapperCodec:
"*":
towardsHost:
mapFrom:
metadata.sag.type : metadata.http.headers.x-apamaeventtype
metadata.sag.channel : metadata.http.headers.x-apamachannel
- jsonCodec
- stringCodec
- httpServer
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:
httpServer:
- apama.eventMap
- mapperCodec:
"*":
towardsHost:
mapFrom:
metadata.sag.type : metadata.http.queryString.eventType
metadata.sag.channel : metadata.http.queryString.channel
- jsonCodec
- stringCodec
- httpServer
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:
httpServer:
- 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
- httpServer
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:
httpServer:
- apama.eventString
- mapperCodec:
"*":
towardsHost:
mapFrom:
metadata.sag.channel: metadata.http.path
- stringCodec
- httpServer
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)'

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.