Transaction message examples for the sending program
This section describes the data in the message that your sending program must produce when you use a Queue data source connector for transaction data. It also provides code samples for creating a transaction message in the required format.
Information required for the transaction message
When you use a Queue data source connector for transaction data, the sending program must provide the following information in the data sent to the queue server.
For AMQP queues, the message has two parts:
- Properties name value pairs including a custom header
- Data as json payload
Name | Value |
---|---|
AUDHASH | Hash for the audienceId generated using a standard hash function. The function must generate
a positive value. Used in the header of a JMS message. Not required for AMQP. |
deploymentConfigurationId | You can obtain the ID of the deployment configuration on the Deployment tab of the workspace.
Select the deployment configuration and select the History tab in the panel that opens. Look under
the Message column for the configuration ID. Used in the header and the body of a JMS message. Required in the AMQP message custom header. |
inputVersion | The input version number entered on the Properties tab of the deployment configuration.
Used in the header and the body of a JMS message. Required in the AMQP message custom header. |
AudienceLevel | The code assigned to the audience level on the Settings > Detect Settings >
Audience Levels page. Used in the header and the body of a JMS message. Required in the AMQP message custom header. |
audienceId | The customer ID associated with this transaction. Used in the header and the body of a JMS message. Required in the AMQP message custom header. |
inputDataSourceName | The name of the data source to which the Queue data source connector is mapped. Data sources are defined
on the Settings > Detect Settings > Data Sources page. Used in the header and the body of a JMS message. Required in the AMQP message custom header. |
transaction | Fields from your Transaction data source, as defined on the Settings > Detect
Settings > Data Sources page. Used in the header and the body of a JMS message. Required in the AMQP message custom header. Note: The date must be expressed in milliseconds.
JMS example:
|
Sample code for creating a transaction message for JMS queue servers
Here is a sample code snippet for creating a JMS message for transaction data using the JMS API.
Line breaks have been added for readability.
//JMS Header Fields
MapMessage message = session.createMapMessage();
message.setLongProperty("AUDHASH",hashcode);
message.setStringProperty("deploymentConfigurationId",
"eecdc1b4-5333-4076-9af6-dc6c2f932c0e");
message.setLongProperty("inputVersion", 5);
//JMS Body Fields
message.setString("deploymentConfigurationId",
"eecdc1b4-5333-4076-9af6-dc6c2f932c0e");
message.setInt("inputVersion", 5);
message.setString("audienceLevel", "audienceLevel");
message.setString("audienceId", "cm00409");
message.setString("inputDataSourceName", "DataSourceNam");
message.setString("transaction", "{\"Date\":1408077610000,\"Amount2\":1000.00,\
"Type\":\"E1a\",\"Amount1\":1009.1,\"ID\":\"cm00409\"}");
Sample code for creating a transaction message for AMQP queue servers
The client must ensure reliable message delivery.
Sender programs send transaction to the input exchange specified during deployment by specifying the routing key. This key should be within the number of engines used by the deployment and should remain the same for the audienece ID (that is, it should be sticky).
For example, if a a deployment has 16 engines, then a routing key should be generated with the following characteristics.
- The key remains the same for each audience I.D
- The key should not be greater than 16.
- The key evenly distributes the load among 16 engine.
One way to generate a routing key is to use the modulo operation. For example, if there are 8 engines then for the audience ID hash the routing key can be calculated as follows. The remainder after division by 8 is the routing key.
Audience ID hash | Modulo operation | Routing key |
---|---|---|
9 | 9 mod 8 | 1 |
11 | 11 mod 8 | 3 |
8 | 8 mod 8 | 0 The routing key starts with 0. |
Line breaks have been added for readability.
int routekey = audience % engineCount+1;
BasicProperties.Builder propsBuilder = new BasicProperties.Builder();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("deploymentConfigurationId", deploymentConfigurationId);
headers.put("inputVersion", inputVersion);
headers.put("audienceLevel", "NOTREQD");
headers.put("audienceId", audienceId);
headers.put("inputDataSourceName", inputDataSourceName);
propsBuilder.headers(headers);
channel.basicPublish("InputExchage", routekey+"", propsBuilder.build(),
dataString.getBytes("UTF-8"));
Example of a transaction message
This is sample input message that was sent to an Active MQ queue server.
Line breaks have been added for readability.
ActiveMQMapMessage {commandId = 0, responseRequired = false,
messageId = ID:ADMINIB-3C6H892-58046-1428399823708-0:0:1:1:1,
originalDestination = null,
originalTransactionId = null,
producerId = null,
destination = queue://amqinput,
transactionId = null,
expiration = 0,
timestamp = 1428399824137,
arrival = 0,
brokerInTime = 0,
brokerOutTime = 0,
correlationId = null,
replyTo = null,
persistent = false,
type = null,
priority = 4,
groupID = null,
groupSequence = 0,
targetConsumerId = null,
compressed = false,
userID = null,
content = org.apache.activemq.util.ByteSequence@60945fea,
marshalledProperties = null,
dataStructure = null,
redeliveryCounter = 0,
size = 0,
properties = {inputVersion=5,
deploymentConfigurationId=eecdc1b4-5333-4076-9af6-dc6c2f932c0e,
AUDHASH=13670},
readOnlyProperties = false,
readOnlyBody = false, droppable = false}
ActiveMQMapMessage
{ theTable =
{audienceLevel=audienceLevel,
audienceId=cm00409,
inputVersion=5,
transaction={"FLAG":true,
"DATE":1408077610000,
"AMT":1000.00,
"NUMBER":10,
"TRANCODE":"ATMD",
"CURRENCY":1009.1,
"ID":"cm00411"}
}