Hi Gordon,
I'm another user and I have similar use case as yours; at present we implemented only for email, but the setup was done taking into account possible extension (SMS, etc.) as you mentioned.
The way I setup, being everything on a Java EE container: I have a dedicated part of the Java EE application where I use Apache Camel framework, and we defined routes which can be "started" from within the knowledge session.
For example, have a route for general email, have another route for high importance email.
Then I have an EJB which is basically proxy-ing methods of Camel's ProducerTemplate, and you can one of these methods be called from within the rule, to send it an email content (the body) with recipients and subject (headers) and to a specific route (the generic or the high importance route).
To obtain a reference to this EJB instance from within the session I believe there are two ways:
- set it as a global
- look it up via JNDI (as a Drools function returning the lookup)
Although I defined the EJB as @Singleton, so I could use the former way, in practice I actually use the latter, this would be preferred in case I will rework it being a @Stateless, like are already some Controllers/"DAO"/etc.
The great thing about Camel framework is that you have Components for virtually anything, and for email (SMTP in this case), twitter, etc. they are on the main trunk.
I personally used so far SMTP Component for sending out emails from Drools, and Twitter for reading tweets into Drools as events.
The thing I like the most, is that Camel "routes" actually provide mechanism to define control flows, throttling, SLAs, etc. in a very neat, clean and maintainable way via its DSL.
I want to stress this point as I found particularly useful to add a "throttler" for outgoing email.
Once a rule loop caused the original setup to send out a bazillion emails, the solution was to implement a
throttler so it would allow a max number of emails per minute. Then we trap exception also as desired in the camel route DSL definition. Obviously I could foresee this potential problem in the first place, I just like to point out the solution was pretty easy to implement thanks to the Camel DSL.
I hope this gives some ideas, and possibly something alternative to Spring? =)
Just a drafted snipped below
Hope this helps
Ciao,
MM
function CamelBootstrapInterface getCamel() {
return (CamelBootstrapInterface) javax.naming.InitialContext.doLookup("java:global/my-javaee-app/CamelBootstrap");
}
rule "Alert means email"
no-loop
when
$a : Alert()
then
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("To", "nob...@acme.com");
headers.put("From", new javax.mail.internet.InternetAddress("dro...@acme.com", "Drools at Acme Inc."));
headers.put("Subject", "ALERT");
StringBuilder sb = new StringBuilder();
sb.append("<html><body><h1>ALERT !!!</h1>");
sb.append($a);
sb.append("</body></html>");
try {
getCamel().sendRouteBodyHeaders("direct:smtp", sb.toString(), headers);
} catch (javax.naming.NameNotFoundException e) {
// uhm...
}
end