Each Microservice uses a separate bounded context with a separate physical database. When running multiple microservices in the same deployment (AKA Flex Package), the system needs to know where to route the DB queries. DataRouting is the term Broadleaf uses to define which DB connection the system should utilize.
To put in other words Data Routing is the dynamic routing for the database based on the entry point. In most cases, the entry point is an API endpoint. Without this routing, the services will not be able to connect to the database.
Let’s say you have 2 services, the first should connect to the “customer” database, and the second to the “order” database. It is possible to run these services separately and specify the DataSource configuration so that each understands what database to connect to. But if you decide to combine these 2 services into 1 (like we do in our flex packages), you will need to somehow specify to each service what database to use. This is where our Data Routing is needed.
You’ll need to setup the DataRoute at the beginning of the request flow. For example, an Endpoint or Message Listener.
One example is to use DataRouteByExample(Order.class)
. This will inspect the package of Order.class to associate this request with the “order” DB configuration. You could also have used @DataRouteByKey(“order”)
for this example.
See com.broadleafcommerce.common.extension.data.DataRouteReference#findRouteByExample(java.lang.Class)
The annotation com.broadleafcommerce.common.jpa.data.JpaDataRoute
is used to configure this routing.
You can find more details about data routing here Broadleaf Dev Central