Skip to content

Simple local Publisher-Subscriber utility for InterSystems IRIS

License

Notifications You must be signed in to change notification settings

intersystems-ib/iris-pubsub

Repository files navigation

Simple local Publisher-Subscriber utility for InterSystems IRIS.

QuickStart

  • Run sample container
docker-compose up -d
  • PubSub uses dc.PubSub.Interop.Production. It's empty.
  • Create some partitions. This is only needed the first time. Check the production again.
do ##class(dc.PubSub.API).AddPartitions(3)
  • Create a topic:
    • You will create a topic called simple/topic.
    • Optionally, you can add a PartitionKey in your topic. This allows you to define which field, in a message published in your topic, will be used to determine the partition that will handle the message.
    • All messages in same partition are processed in order.
set topic = ##class(dc.PubSub.API).CreateTopic("simple/topic", { "PartitionKey": "patientId" })
  • Create some subscribers to your topic.
  • These subscribers are class methods that will be called each time a message is published in the topic you created.
  • The endpoint to specify your subscriber goes like this: <namespace>:<package>:<classmethod>
do ##class(dc.PubSub.API).CreateSubscription("simple/topic", { "Protocol": "ClassMethod", "Endpoint": "USER:dc.PubSub.Test.Simple:Subscriber"})
do ##class(dc.PubSub.API).CreateSubscription("simple/topic", { "Protocol": "ClassMethod", "Endpoint": "USER:dc.PubSub.Test.Simple:Sub2"})
  • Publish some messages to your topic
do ##class(dc.PubSub.API).Publish("simple/topic", {"patientId": "HA98744455", "data": "dummy" } )
do ##class(dc.PubSub.API).Publish("simple/topic", {"patientId": "12TFFFHM88", "data": "dummy999" } )
  • Check messages in your production

  • Also, check included ^zlog global:

zw ^zlog
^zlog=4
^zlog(1)="[dc.PubSub.Test.Simple:Subscriber] Received: {""patientId"":""HA98744455"",""data"":""dummy""}"
^zlog(2)="[dc.PubSub.Test.Simple:Sub2] Received: {""patientId"":""HA98744455"",""data"":""dummy""}"
^zlog(3)="[dc.PubSub.Test.Simple:Subscriber] Received: {""patientId"":""12TFFFHM88"",""data"":""dummy999""}"
^zlog(4)="[dc.PubSub.Test.Simple:Sub2] Received: {""patientId"":""12TFFFHM88"",""data"":""dummy999""}"

Installation

  1. Install IPM package manager if you don't have already done it.
  2. Create a new namespace (e.g. TEST). iris-pubsub needs to be installed in a new namespace because it runs its own interoperability production.
  3. Switch to your new namespace and run:
TEST> zpm
zpm:TEST> install iris-pubsub
  1. Setup how many partitions (Business Service - Business Operation) you want to run:
TEST> do ##class(dc.PubSub.API).AddPartitions(3)

And you are done, check the QuickStart section for some examples.

About

Simple local Publisher-Subscriber utility for InterSystems IRIS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published