I am trying to build a generic notification service for sending different notifications(Email, SMS or Mobile Push) to clients whenever some event happens. This service would be in turn calling a publisher/ subscriber event based system somewhat similar to this: https://sites.google.com/site/jeffhartkopf/notifier. Whenever some event happens, it gets published on SQS from where the subscriber reads it and sends the notification.
API interface for publisher:
Notification Sender class would have:
sendNotification(Object payload, Map attributeMap)
Here, the payload contains the parameters that are variable in text of Email/SMS/push notification template. For example: If email has "Hello $name", the payload object would have name as a field and value set as the name of the client you wish to send the notification to:
@EventType("name"= "Recommendations")
class PayloadObject {
@Getter @Setter
String name;
}
Here, Event type is custom annotation to know the type of event for which notification is to be sent, which clients are expected to use while sending their payload objects.
- Transformers: Now to publish an event we need serialized JSON or XML Strings which will be published. So I thought of taking the Object payload from clients of my service and using JSON or XML transformers in my service based on the event type and templates. Attribute map is for extra information like email attachment files which you do not want to parse from Json or xml serialized objects. For bulk data payloads will be used.
The problem I see in this approach is that Object payload is too generic that there would be no type safety at all. Like the clients of this service can send in junk objects and there would not be any checks that I can think of to validate this in my service. Is there a way I can validate the parameters in templates (Velocity or XSLT format) against the object that is being sent by clients. Like may be making the client write unit tests corresponding to each template and payload Object? Or can I model my API in a better way rather than taking an Object from the client to ensure type safety while calling my API.