The attached file contains two $system.Event examples that processes work asynchronously using persistent queues:
- Events_Simple.prj.xml
- Events_PubSub.prj.xml - updated this example has been published on https://github.com/intersystems-ib/cache-iat-pubsub
Events_Simple
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=10 ^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) 1 write $system.Process.Terminate(18184) 1
Classes:
- 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
Events_PubSub
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:
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:
P.S.
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 (
) 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
)
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.
Please upload these samples on GitHub.
Great article, Alberto!
Please upload to Github.
Glad to see usage of UML Explorer ;)
Hi all,
I've just published the PubSub example in:
https://github.com/intersystems-ib/cache-iat-pubsub
Another queue processing sample is now available in this GitHub repository, courtesy of Vladimir Prushkovskiy.