Service - Activity Switchboard: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
No edit summary
Line 12: Line 12:


=== Configuration tags ===
=== Configuration tags ===
<syntaxhighlight lang="JavaScript">
{
configKey: "PendingMsgCfgPause"
configTag: "PendingMsgCfgPause"
configValue: xx //number of ?seconds to wait between attempts to pullMsgCfg
}
</syntaxhighlight>


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">
Line 26: Line 18:
configTag: {serviceName}_{topicName}
configTag: {serviceName}_{topicName}
configValue: {msgCfg}
configValue: {msgCfg}
configValue: {
pending: true
nextCheck: {timestamp}
}
configValue: {
deleted: true
timestampDeleted: {current timestamp}
}
timestampUpdated = zz
timestampUpdated = zz
}
}
Line 39: Line 23:
: propogated from [[Service - Message Config Manager|Message Config Manager]] service
: propogated from [[Service - Message Config Manager|Message Config Manager]] service
: see [[Standard message config for In Out topics]]
: see [[Standard message config for In Out topics]]
: if the MsgCfg has not been dug before set it to pending, each time a message comes in a request is made using pullMsgCfg Lambda, if the request is not successful set nextCheck = current timestamp + PendingMsgCfgPause
: timestampUpdated is used to ensure the latest msgCfg update is applied
: timestampUpdated is used to ensure the latest msgCfg update is applied


Line 46: Line 29:
* Groups many triggers, all triggers for a trigger group must pass for the trigger group to pass
* Groups many triggers, all triggers for a trigger group must pass for the trigger group to pass
* no sort key
* no sort key
* if multiple values are sent for a trigger we consider this an "or" check, any of the values can match. We do this by saving each value as a separate trigger, then when checking a trigger groups child triggers we have a counter that enables a check if any one of the values matches


=== Fields ===
=== Fields ===
Line 66: Line 50:
; triggerId
; triggerId
: (partition key)
: (partition key)
: comes from: {"attributes"|"property"}_{hash of propertyName}_{hash of propertyValue}
: comes from: {hash of valueType(property|attribute).propertyName}_{hash of propertyValue}
: or: serviceName_{value of serviceName}
: or: serviceName_{hash of serviceName value}
: or: topicName_{value of topicName}
: or: topicName_{hash of topicName value}
: attributes is for message attributes
: attributes is for message attributes
: property is from the data sent inside the message body
: property is from the data sent inside the message body
Line 88: Line 72:
* msgCfgs get updated from [[Service - Message Config Manager|Message Config Manager]] service, we do this by subscribing to Message Config Manager's OutMsgCfgUpdate topic
* msgCfgs get updated from [[Service - Message Config Manager|Message Config Manager]] service, we do this by subscribing to Message Config Manager's OutMsgCfgUpdate topic
* Only want to process messages from certain In/Out topics, it will be most topics but does not have to be all
* Only want to process messages from certain In/Out topics, it will be most topics but does not have to be all
* Set which topics to subscribe to by creating a "MsgCfg" record in the Config table, initially the configValue will be empty and needs to be pulled from Message Config Manager
* Set which topics to subscribe to by setting activitySwitchboard = true in msgCfg
* Plan is to set a list of topics in InitalSetup, for each add a record to Config table and invoking [[2020-11-08 - Message Config Manager - Functions#getMsgCfgs]] or getMsgCfg, not sure how to do this to ensure the configs already exist
* Could also perhaps have a placeholder configValue that states the MsgCfg has not yet been dug, when a message comes in if that is set, request the MsgCfg then, if the request is unsuccessful have another placeholder that has timestamp when last checked, after a certain time re-request (and probably DLQ the message that arrived)
* If MsgCfg is ever added after initial deploy, also need to add receiveMsg subscription to that topic, perhaps build config Lambda to handle this


= Ideas =
= Ideas =

Revision as of 14:03, 10 May 2021

Overview

Receives most messages sent within the entire project's serverless flow, allows services to register a set of triggers that are checked when each message is received, if all triggers pass a message is sent out for subscribed services.

Repository

https://bitbucket.org/stb_working/activity-switchboard/src/master/

DynamoDB tables

Standard Config Table Per Service

Configuration tags

{
	configKey: "MsgCfg"
	configTag: {serviceName}_{topicName}
	configValue: {msgCfg}
	timestampUpdated = zz
}
propogated from Message Config Manager service
see Standard message config for In Out topics
timestampUpdated is used to ensure the latest msgCfg update is applied

TriggerGroups

  • Groups many triggers, all triggers for a trigger group must pass for the trigger group to pass
  • no sort key
  • if multiple values are sent for a trigger we consider this an "or" check, any of the values can match. We do this by saving each value as a separate trigger, then when checking a trigger groups child triggers we have a counter that enables a check if any one of the values matches

Fields

triggerGroupId
(partition key)
comes from: {receiverTag}_{uniqueId}
uniqueId comes from receiver service, eg: {notificationId}, cannot include underscores
triggers
array of objects (DynamoDB list?)
each element has triggerId, propertyName, and propertyValue
additionalData
set by the receiving service, gets added to activity messages send to receiving service
could include id/s needed by the receiving service to match the trigger to its entity

Triggers

Fields

triggerId
(partition key)
comes from: {hash of valueType(property|attribute).propertyName}_{hash of propertyValue}
or: serviceName_{hash of serviceName value}
or: topicName_{hash of topicName value}
attributes is for message attributes
property is from the data sent inside the message body
hash property name and value so no ambiguity about underscores/spaces etc..
triggerGroupId
(sort key)
propertyName
propertyValue

Efficiency

  • Service will result in a large number of queries to Triggers table, every message will need to make a query for every field set as an activityTrigger
  • Try to make this as efficient as possible
  • To reduce number of queries made to Tiggers table we use the msgCfg for any message received
    • MsgCfg sets which properties can be used as triggers, others are not queried

Handling msgCfgs

  • msgCfgs get updated from Message Config Manager service, we do this by subscribing to Message Config Manager's OutMsgCfgUpdate topic
  • Only want to process messages from certain In/Out topics, it will be most topics but does not have to be all
  • Set which topics to subscribe to by setting activitySwitchboard = true in msgCfg

Ideas

  • If more efficient can use cache for regular DynamoDB queries
  • Could add other matching methods such as greater than or less than, in DynamoDB this might be more efficient to add as separate table with its own structure, eg: partition key is the field reference, sort key is the amount, then use sort key to return matching triggers. Danger of bad partitioning in DynamoDB (or hitting limits) due to large numbers of sort keys associated with one partition key
  • could consider how to incorporate includes or checking within a set of options set in the trigger, again might need specialized table structure
  • Might be able to optimise by using SNS > stream instead of SNS > SQS for all incomming messages
  • One system level receiving service could be specialized logs, eg logs per service per user/per product/etc
  • Topic name is not fixed part of the TriggersGroup structure, allow for trigger groups that are not connected to specific topics, but can pass messages from any topic that matches other triggers

Working documents

Working_documents - Activity Switchboard