Simple $system.Event examples

The attached file contains two $system.Event examples that processes work asynchronously using persistent queues:


This is a very basic example that creates some worker processes and then enqueue messages to them using $system.Event.

; create shared resource, create worker jobs.
USER>do ##class(IAT.S04.Event.Test).Setup()
; enqueue some messages to workers and see what happens
USER>do ##class(IAT.S04.Event.Test).Run()
Show log? no/[yes]:
^Samples.Log(1)="[2016-02-19 09:43:14] Enqueuing 1"
^Samples.Log(2)="[2016-02-19 09:43:14] Worker 8168 grabs: 1"
^Samples.Log(3)="[2016-02-19 09:43:14] Enqueuing 2"
^Samples.Log(4)="[2016-02-19 09:43:14] Worker 18184 grabs: 2"
^Samples.Log(5)="[2016-02-19 09:43:14] Enqueuing 3"
^Samples.Log(6)="[2016-02-19 09:43:14] Worker 8168 grabs: 3"
^Samples.Log(7)="[2016-02-19 09:43:14] Enqueuing 4"
^Samples.Log(8)="[2016-02-19 09:43:14] Worker 18184 grabs: 4"
^Samples.Log(9)="[2016-02-19 09:43:14] Enqueuing 5"
^Samples.Log(10)="[2016-02-19 09:43:14] Worker 8168 grabs: 5"
; we are done. we could enqueue more messages or just kill worker jobs.
write $system.Process.Terminate(8168)
write $system.Process.Terminate(18184)


  • Manager - methods to create shared resources and workers as well as to enqueue messages to workers.
  • Queue - simple persistent class used to store messages
  • Worker - worker class that waits for an event and processes the received message


This example is based on the same foundations as Events_Simple.

The goal here is building a simple Publisher-Subscriber model.  

There are two subscribers:

  • SubPatient which handles Patient related messages.
  • SubDummy which handles dummy messages.
; create events and subscriber jobs
do ##class(IAT.S05.PubSub.Example.Main).Setup()
; send some messages to channels
do ##class(IAT.S05.PubSub.Example.Main).Run()
; show log
zw ^PubSub.Log

Main classes:

Example classes:


Example Log


I love this! I needed PubSub-like services for the concurrent tweets processing and control of workers in the twitter api streaming mode sample and at the moment there is fragile, simplistic locking  schema used. I suspect PubSub will be better/more reliable, so I'll try to play with your classes.

But here are 1 questions:

  • why you didn't upload them to your intersystems-ib github repo?
  • and why these strange package names - IAT.S04.* and IAT.S05.*?


It would be really nice if you would explain more details about API usage: I understand that UMLExplorer diagrams created are obvious and self-explanatory (wink) but more documentation never hurts... 

Hi Timur,

I have many examples that we have been using during ad-hoc sessions with customers in Spain.

Those sessions were called IAT (you know we tend to pick up tricky names smiley)

And at this moment they are not in our github repository, so I'm just sharing some of them here.

We could upload some of these examples to github and use proper names if you are interested.