question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Same entity name in several MicroServices collide in the Gateway

See original GitHub issue
Overview of the issue

When doing microservices, you often find the same entity name but with different purposes. For example, a Customer in the Invoice microservice, does not have the same attributes/methods as a Customer in the Shipping microservice.

When those two Customer entities are generated in the Gateway, they collide: only the last one remains. So it makes it totally unusable to have the same entity name in different services.

Motivation for or Use Case

We have an architecture with a few microservices. Following some DDD principles, we end up with a few similar entity names, but doing different things (eg. Customer, Document, Service, Event…). They have the same name because it’s important for our business, but they have totally different attributes.

We would need the Gateway to make a clear separation between those β€œsimilar” entities (in terms of TypeScript code, and in terms of graphical components and menus).

Reproduce the error

Create an Invoice microservice and import the following JDL :

entity Customer {
    firstName String,
    lastName String,
    company String,
    linkedInUrl String
}

Create a Shipping microservice and import the following JDL:

entity Customer {
    firstName String,
    lastName String,
    gender Gender,
    blogUrl String,
    twitterUrl String,
    githubUrl String
}

enum Gender {
M, F
}

Now, create a Gateway, import first the Invoice JDL, and then the Shipping JDL. Only the Customer from Shipping will remain.

Related issues
Suggest a Fix

One easy fix would be for us to have different entity names. Instead of Customer, we could have ShippingCustomer and InvoiceCustomer. But this is not acceptable.

One fix would be to have different packages (based on the baseName of the microservice). For example, on the web part of it, instead of having :

gateway/src/main/webapp/app/entities/customer

We would have a sub-package with the baseName of the microservice:

gateway/src/main/webapp/app/entities/invoice/customer
gateway/src/main/webapp/app/entities/shipping/customer

There is also one and only one β€œCustomer” entry in the β€œEntities” menu. There should be two (with sub-menus)

JHipster Version(s)
gateway@0.0.0 /Users/agoncal/Documents/Code/Temp/jhipster/buggateway/gateway
└── generator-jhipster@4.9.0 

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "org.demo.gateway"
    },
    "jhipsterVersion": "4.9.0",
    "baseName": "gateway",
    "packageName": "org.demo.gateway",
    "packageFolder": "org/demo/gateway",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "hazelcast",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Memory",
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": "eureka",
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "replaced-by-jhipster-info",
    "clientFramework": "angularX",
    "useSass": false,
    "clientPackageManager": "yarn",
    "applicationType": "gateway",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": false
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Customer (customer) {
  firstName String,
  lastName String,
  company String,
  linkedInUrl String
}




Environment and Tools

java version β€œ1.8.0_131” Javaβ„’ SE Runtime Environment (build 1.8.0_131-b11) Java HotSpotβ„’ 64-Bit Server VM (build 25.131-b11, mixed mode)

git version 2.14.2

node: v8.6.0

npm: 5.3.0

bower: 1.8.0

gulp: [21:40:22] CLI version 1.3.0

yeoman: 2.0.0

yarn: 1.1.0

Docker version 17.09.0-ce, build afdb6d4

docker-compose version 1.16.1, build 6d1ac21

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

5reactions
jduboiscommented, Oct 9, 2017
  • as @deepu105 says this has never been thought of
  • and @agoncal I agree having a prefix is better

Who’s OK for doing the prefix solution? Please vote πŸ‘ on this comment, and help on a PR if you can.

  • I have no idea of the work this involves, but at least it needs quite a lot of tests
  • this is going to be breaking change for many people
0reactions
agoncalcommented, Nov 16, 2017

@deepu105 I just regenerate my app with the latest version of JHipster. Now, all my components directory are suffixed with AngularJS suffix. So, under entities instead of:

β”œβ”€β”€ entities
β”‚   β”œβ”€β”€ address
β”‚   β”œβ”€β”€ contact
β”‚   β”œβ”€β”€ tenant
β”‚   └── venue

I have

β”œβ”€β”€ entities
β”‚   β”œβ”€β”€ address-sponsor
β”‚   β”œβ”€β”€ contact-sponsor
β”‚   β”œβ”€β”€ tenant-sponsor
β”‚   └── venue-sponsor

And because in my entities json files I have:

    "microserviceName": "sponsor",
    "angularJSSuffix": "sponsor"

I now have my modules that are named SponsorEventSponsorModule (the first Sponsor being the microservice name, the second Sponsor being the Angular suffix). We were worried about the merge issue if subdirectories were introduced, but now, with different directory name, we’ll have the same merge issues.

I still think that subdirectories would be better. An easy one would be:

β”œβ”€β”€ entities
β”‚   β”œβ”€β”€ sponsor   // microservice name
β”‚   β”‚   β”œβ”€β”€ address
β”‚   β”‚   β”œβ”€β”€ contact
β”‚   β”‚   β”œβ”€β”€ tenant
β”‚   β”‚   └── venue

A better one (well, in my opinion)

β”œβ”€β”€ sponsor   // microservice name
β”‚   β”œβ”€β”€ entities
β”‚   β”‚   β”œβ”€β”€ address
β”‚   β”‚   β”œβ”€β”€ contact
β”‚   β”‚   β”œβ”€β”€ tenant
β”‚   β”‚   └── venue

BTW I’ve created an issue about directory structure in general https://github.com/jhipster/generator-jhipster/issues/6693

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the purpose of generating an Entity into the Jhipster ...
I saw in many tutorials that we need to go back to gateway and generate an entity after generating a microservice application with...
Read more >
How To Configure API Gateway in Microservices Architecture
An API gateway helps to separate the external APIs from the internal microservices patterns. It hides the service history and versioningΒ ...
Read more >
Implementing Domain-Driven Design for Microservice ...
Our approach was to put some structure around getting to understand the business domain by analyzing the domain, defining the bounded contexts, defining...
Read more >
Architecting multiple microservices behind a single domain ...
With a single AWS account, the microservices can share the same networking topology, and so more easily communicate with each other when needed....
Read more >
The macro problem with microservices - Stack Overflow Blog
Every company is now expected to have software products. ... Developers began to realize that microservices came with some serious drawbacksΒ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found