Wednesday, August 12, 2026

#1162 - Use of Semaphores in OIC Part II

 

Introduction

This post looks at implementing the singleton pattern via semaphores. It leads on from the previous post, which you really should read, before continuing.

The use case is very simple - an async integration that can only run as a singleton.

Here is the integration - 

As you can see, the singleton rule applies to the createOrderScope, Commiskey Inc. is an old fashioned company that likes creating orders for our craft beers one at a time.

I acquire the semaphore before executing the createOrderScope. It is released, on completion.

The only logic I have in the scope is a WAIT and a LOG; the LOG outputting order creation time.


As mentioned in the previous post - channel and name are unique. So, for this use case, I can hardcode them in a lookup - 


I use the instanceId as the requestor -

The instanceId can be found here - 

I'll invoke the integration twice, with orderNr set to 2112 and 2113 - 

Let's check the instance ids - 


Let's check the timestamps for order created -

Here we see the 30 second delay - 

I'll run again to get some screenshots from the Semaphore control, this time with orders 2525 and 2526 - 

Here the holder is set to the instance id of the flow for orderNr 2525.

Note we have 1 message in the backlog - 

Here we see the acquire request from the orderNr 2526 flow.

Ca. 30 seconds later - 

The 2nd instance has acquired the semaphore.

The 2nd flow has released the semaphore.

Here's the view from the acquire and release semaphore side of the house - 

As you can see, the first acquire only took 1.2 seconds. The 2nd, 26.37 seconds - 

For the 2nd instance - note the WHILE loop - executing until the semaphore can be acquired.

Summa Summarum

This is a simple POC, but it does illustrate what can be achieved. Note, the acquire semaphore integration is synchronous, so one needs to be aware of possible timeouts after 5 minutes. However, this could still be useful for many use cases.

Cerevisia Aestiva

This brewery, from the old town of Neumarkt in the Oberpfalz, has been going since 1628. It is still family owned and prides itself on only using organic ingredients in its beers. They produce bottom-fermented beer as well as top-fermented beer. The latter uses Saccharomyces cerevisiae yeast, while the former uses Saccharomyces pastorianus yeast. Bottom-fermented beers are your Pils and Lagers, while top-fermented beers are your Weissbiers, Ales and Stouts of this world. Bio Urstoff is the one I tend to drink - a perfect mix of hops and malt.   





 




























No comments: