简体   繁体   中英

architecture microservice spring boot

I am working with Spring cloud (microservices) and I have implemented security with JWT token. in my security application, I have entities like User, Role and UserRole. so Every request first comes to the ZOOL service and it calls Authentication service and Authentication service creates/returns JWT token. Also, I have another microservice-rest application (Questions-app) that needs JWT token. in the Questions-app I have a Question entity that contains authorId field.

@Entity
@Table(name="QUESTION")
public class Question {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID", updatable = false, nullable = false)
    private long id;

    @Column(name = "AUTHOR")
    private long authorId;

    @Column(name = "TITLE")
    private String title;
}

Now, it is not clear for me, is it right to set authorId long type or I should create User, Role, UserRole entities (just simple copy from AUTH project) in the questions-app and set "AUTHOR" column like that

 @OneToOne
 @JoinColumn(name="AUTHOR")
 private User user;

I know that in the first option when I need show question and user's name on the webpage, then I should call 2 services (one from question-app (fetch question) and another from auth service (fetch user information by author id) I would like to know what is the best practises?

If you have common database for all of these microservices and you need User related information based on question id.

Then instead of doing another database call for user, you can directly do @OneToOne to User.

From your question it is better to go for 2 option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM