I’ve been circling the best approach for integrating an external service into my domain.
There are a number of third-party services that can be used, so we have an Adapter providing a common interface. We only have X number of instances of the service available at any one time (they are expensive to create and destroy) so they are retrieved from a Pool.
The external service is used as part of a long running process. This process will be implemented with a process manager. An entity is scheduled, it then asks the Object Pool for a resource, when the resource is free it performs an action, the result is then recorded, and resource returned to the Pool. Two parts of this process (the request for a free resource and executing an action) can take some time and are blocking calls. So ideally these should be done asynchronously?
This implies the external service needs to raise events when a resource is free, and when a result to the action has been calculated. Every example I see provides guidance on raising events from aggregates. Very little when an external system (in this case a Generic Subdomain?) needs to report events… So my questions:
My understanding is that any external service is basically a separate bounded context. In which case the Adapter and Pool are basically functioning as an ACL, by hiding the service behind a common interface. Is this assumption correct?
I need to raise events from my Adapter / Pool wrapping the external service. ACLs are often implemented as Domain Services, but the common advice is not to raise events from a Service. My reasoning is the Domain Service is an interface, and the Implementation (Infrastructure) goes ahead and raises events as needed. These are essentially Integration Events as opposed to typical Domain Events. I don’t own the BC, just the Adapter, so the typical guidance on Domain Events / Aggregates goes out the window? Just raise the event directly?
In the instance of the Process Manager requesting a resource from the Pool. Does the Process Manager just call the Adapter directly? Or should this be a Command? Even if the Command is essentially just going to request a resource (ie. no state change to an entity).
Any best practises for raising events in this type of scenario? Likewise, if I decided to implement a supporting subdomain with basic Transaction Script. Assume you would just raise the events directly to the Bus as needed from the ACL. There is no Domain Model, and so everything is an Integration Event?
Purely for theoretical purposes, as I better try to understand the concepts. A Repository is essentially wrapping a third party persistence service. Is the line of reasoning that the persistence technology is a Bounded Context, and the Repository an ACL / Adapter technically correct?
I’ve struggled to find much concrete guidance out there on the above, so any advice is appreciated.