This is a component which make it easier to integrate Jabber/XMPP server with other, third-party tools. It simply allows you to send stanzas from your application without implementing any Jabber/XMPP specific code. The component regularly reads specified data source for XMPP packets to send. The data source can be an SQL database, directory on your filesystem or anything you might want. If you have Web application for example which you want to send notifications of any event to selected users you can install StanzaSender component on your Tigase server. It will help you to easily distribute your messages to end-users.
How it worksThe module itself doesn't do anything. It just schedules tasks and sends stanzas which come from... it doesn't know. To do actual work of retrieving stanzas from data source the component uses tasks. In theory the task can retrieve XMPP packets for sending from any location or may just generate stanzas on its own. In practise there are 2 tasks already implemented and ready to use. You can treat them as a sample code for implementation of your own tasks customised for your specific needs or you can just use these tasks as they are. The tasks which are available are:
FileTaskretrieving stanzas from directory in file system.
JDBCTaskretrieving stanzas from SQL database.
FileTaskimplements tasks for cyclic retrieving stanzas from a directory and sending them to the StanzaHandler object. It looks for any new stanza to send. Any single file can contain only single stanza to send and any entry in database table can also contain only single stanza to send. File on hard disk and record in database is deleted after it is read. Any file in given directory is treated the same way - Tigase assumes it contains valid XML data with XMPP stanza to send. You can however set in configuration, using wildchars which files contain stanzas. All stanzas must contain complete data including correct "from" and "to" attributes. By default it looks for
/var/spool/jabber/folder but you can specify different directory name in initialization string. Sample initialization strings:
/var/spool/jabber/*The last is equal to:
/var/spool/jabber/Note the last forward slash '/' is required in such case if the last element of the path is a directory. Please note! Tigase must have writing permissions for this directory, otherwise it may not function properly.
JDBCTaskimplements tasks for cyclic retrieving stanzas from database and sending them to the StanzaHandler object. Database table format:
- id - numerical unique record indetifier.
- stanza - text field containing valid XML data with XMPP stanza to send.
xmpp_stanzatable but you can specify different table name in connection string. Sample connection string:
jdbc:mysql://localhost/tigasedb?user=tigase&password=pass&table=xmpp_stanzaPlease note the last parameter which is specific to
JDBCTask. You can specify the table name which stores stanzas for sending. If omitted default value is:
ConfigurationIt is Tigase component so the configuration is similar to configuration of all other components. The simplest way to get the settings for StanzaSender is by generating configuration with all possible components. To do this you have to run Tigase server with
--gen-config-allparameter set. By default this component name is ssend and here is a content of the configuration file for StanzaSender: It is one of
<entry type="String" key="id-names"> ... <item value="ssend"/> </entry>To activate the component and specify class name for it following entries has been added:
<entry value="true" type="Boolean" key="ssend.active"/> <entry value="tigase.server.ssender.StanzaSender" type="String" key="ssend.class"/>And the main settings section for the component:
<component name="ssend"> <map> <entry value="10" type="Long" key="default-interval"/> <entry value="1000" type="Integer" key="max-queue-size"/> <entry type="String" key="stanza-listeners"> <item value="jdbc"/> <item value="file"/> </entry> </map> <node name="file"> <map> <entry value="true" type="Boolean" key="active"/> <entry value="tigase.server.ssender.FileTask" type="String" key="class-name"/> <entry value="/var/spool/jabber/*.stanza" type="String" key="init-string"/> <entry value="10" type="Long" key="interval"/> </map> </node> <node name="jdbc"> <map> <entry value="true" type="Boolean" key="active"/> <entry value="tigase.server.ssender.JDBCTask" type="String" key="class-name"/> <entry value="jdbc:mysql://localhost/tigase?user=tigase& password=mypass&table=xmpp_stanza" type="String" key="init-string"/> <entry value="10" type="Long" key="interval"/> </map> </node> </component>I think most of parameters should be pretty clear but some may need a little explanation. General
- default-interval number which specifies in seconds how often should the task look in data source for new packets to send.
- max-queue-size is a number which specifies internal packets queue size. This is used to prevent the component from consume all the memory for data in case the component can not process them.
- stanza-listeners is a list of task names to load. Each task can read XMPP packets to send from different data source. You can load as many listeners (tasks) as you need. Each task must read stanzas from different data source.
stanza-listenerslist there is a separate section with parameters for each task:
- active boolean switch allowing you to turn on/off the task without removing configuration completely.
- class-name Java class name which implements the task. This class must extend
tigase.server.ssender.SenderTaskand it is loaded at runtime.
- init-string is kind of data source connection string. For database it is just database connection string, for file system this is just a directory name. It may be even different for different tasks. The 2 tasks already implemented have some specific features:
FileTaskallows you to use wild-chars in directory/ file name specification and
JDBCTaskallows you to specify additional parameter at the end of JDBC connection string - database table name. For specific examples look at above config sections.
- interval is a number which allows you to specify different interval in seconds for checking data source for each task.