Open Closed

Microservice comunication loop #7289


User avatar
0
andmattia created

I have 2 microservices. In one of them, I expose an API to geolocate a point via GMaps.

So now I'm in this situation:

  • Service 1, where the geolocation API is deployed, needs information from Service 2.
  • Service 2, in some cases, needs to geolocate its data.

I can't reference my application contract from Service 1 in Service 2, and at the same time, I can't add the contract from Service 1 to Service 2. I tried to call my HttpClient from the Domain, but I can't check permissions and still have a 401 issue.

So my questions are:

  • Is it correct to call a service (via HttpClient) in the Domain module? Or is it better to call HttpClient only from the Application?
  • In this case, do I need to redesign the architecture and isolate my geolocation service to be called separately by Service 1 and Service 2? Or should I call it via EventBus? If I call it via EventBus, I don't need to import permissions in the application contract.

5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You can check the document

    https://docs.abp.io/en/commercial/latest/startup-templates/microservice/interservice-communication

  • User Avatar
    0
    andmattia created

    I’ve checked the documentation, but it’s not clear and the pattern we need to solve is not covered. My question is more related to best practices and potential bottlenecks.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I don't know much about your solution structure and user cases.

    I would suggest that services not depend on each other, you can consider refactoring the structure.

    I can't add the contract from Service 1 to Service 2. I tried to call my HttpClient from the Domain, but I can't check permissions and still have a 401 issue.

    You need to add the current user's access_token to the request header

  • User Avatar
    0
    andmattia created

    When you say ‘I would suggest that services not depend on each other,’ do you mean that each service must be independent? Should I use events via a buffer to get data from other services? But generally speaking, if I need to check the stock level and the stock level is managed by the stock service, how can I achieve that?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I mean don't rely on each other, they can one-way dependency

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38