I have a design question related to my earlier post regarding subscribing to external vendor data and publishing it to RabbitMQ.
I currently have an Entrypoint that handles everything related to the external vendor data. When the Entrypoint is first setup, it reads the list of subscriptions from a database, then open a session with the external data vendor, providing the indicated subscription list. Finally, it repeatedly calls next_data() on the vendor session in an infinite loop, triggering the associated service method with each data point arrival.
As you can guess, this is a poor design because the external vendor session is completely locked inside the Entrypoint. If the subscription list has changed, there is no way for re-subscription to occur without restarting the entire service.
My plan is as follows:
Refactor the code related to the external vendor data into a separate dependency, and bind it up in a DependencyProvider. This dependency will essentially expose 2 methods:
- next_data() - return the next point published by the external vendor. This method could be called repeatedly by the Entrypoint class, which would now be much smaller, and only concern itself with what to do when a new data point arrives.
- resubscribe() - refresh the subscription list from the database and resubscribe with the external vendor. This method could be called by a service method listening on a typical RabbitMQ queue. When the appropriate RabbitMQ message arrives, resubscription occurs.
My questions relate are pretty much all variations on, “is this possible / proper design”:
- Are Entrypoints allowed to have dependencies?
- Can an Entrypoint and a Service share a dependency?
If there answer to any of these is no, any suggestions you have to achieve a similar goal would be most appreciated.