Configuring jAlarms with Spring is very simple. Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- This is to enforce the Required and PostContruct annotations -->
<context:annotation-config />
<!-- this channel will send alarms to the recipients defined in the mail template -->
<bean id="alarmMailChannel" class="com.solab.alarms.channels.MailChannel">
<property name="javaMailSender" ref="javaMailSender" />
<property name="mailTemplate"><bean class="org.springframework.mail.SimpleMailMessage">
<property name="subject" value="My server application ALARM" />
<property name="from" value="do-not-reply@mydomain.com" />
<property name="text"><value>My application has send this ALARM: ${msg}
This notification has been automatically sent, do not reply.
</value></property>
<!-- This is obviously very important -->
<property name="to" value="sysadmin@mydomain.com" />
</bean></property>
</bean>
<!-- this channel will send alarms to everyone in the account's contact list -->
<bean id="alarmMsnChannel" class="com.solab.alarms.channels.MsnChannel">
<property name="username" value="someMsnUsername" />
<property name="password" value="password" />
</bean>
<!-- this channel will post the alarms as the status in the Twitter account -->
<bean id="twitterChannel" class="com.solab.alarms.channels.twitter.TwitterChannel">
<property name="accessToken" value="theAccessTokenYouGetByRunningThe_TwitterAuth_Program" />
<property name="tokenSecret" value="TheSecretObtainedFromThe_TwitterAuth_programIncludedWithTheLibrary" />
</bean>
<bean id="alarmSender" class="com.solab.alarms.AlarmSender">
<property name="alarmChannels"><list>
<ref local="alarmMailChannel" />
<ref local="alarmMsnChannel" />
<ref local="twitterChannel" />
</list></property>
</bean>
</beans>
And then you just inject the alarmSender bean into any component that wants to use it to send alarms. In this example, any alarm will be sent by email to sysadmin@mydomain.com, to all the contacts of the MSN user someMsnUsername, and posted as the status of the user you created for the app in Twitter (Twitter does not directly use the username/password of the user; it uses OAuth which is a little more convoluted but a little more secure).
© 2009 Enrique Zamudio