Coder Social home page Coder Social logo

cache-iat-pubsub's Introduction

Caché Publisher - Subscriber

The purpose of this repository is to provide a simple example of Publisher-Subscriber model implemented using InterSystems Caché.

This example came out of a session which discussed ways of processing work asynchronously using persistent queues.

Installation

set path="C:\Temp\cache-iat-pubsub-master\cache"
do $system.OBJ.ImportDir(path,"*.inc","ck",.error,1)
do $system.OBJ.ImportDir(path,"*.xml","ck",.error,1)

Run the code

; 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
zwrite ^PubSub.Log

Implementation

Caché Event API is used to let the subscriber processes sleep until they are notified.

Main classes

  • Manager - handles core operations such as adding subscribers, terminate all subscriber jobs, etc.
  • Publisher - generic publisher, provides a basic Send operation which notifies a subscriber that a message is ready.
  • Subscriber - generic subscriber, all subscriber must extend from this.

Example classes

The following classes provides an example of how the main classes could be used, in this case there are two subscribers:

  • SubPatient which handles Patient related messages.
  • SubDummy which handles dummy messages.

Log

After running the example, the log stored in ^PubSub.Log global will look similar to this:

Further discussion

There are several points of this example that can be discussed as an exercise:

Caché Event API vs Semaphores

  • $system.Event (Caché Event API) can only wait / wake up resources on the same system (not networking supported).
  • It would be interesting implementing this same model using $system.Semaphore over an ECP scenario.

Multiple types of subscribers

  • In IAT.PubSub.Publisher:Send() method, it simply creates a message header, save it to queue and send a signal to one of the subscribers.
  • It would be interesting allowing more than one type of subscriber per channel. In this case, the Send() method should create several message headers and signal the different types of configured subscribers.

Developer Community

Have a look at InterSystems Developer Community to learn about InterSystems technology, sharing solutions and staying up-to-date on the latest developments.

This example was published in https://community.intersystems.com/post/simple-systemevent-examples

cache-iat-pubsub's People

Contributors

evshvarov avatar gevorg95 avatar isc-afuentes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.