我目前正在開發(fā)一個(gè) Spring Boot 應(yīng)用程序。我為 httpBasic 身份驗(yàn)證實(shí)現(xiàn)了 Spring Boot 安全性。身份驗(yàn)證成功后,我的自定義過濾器方法會(huì)被調(diào)用。protected void onSuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Authentication authResult) throws IOException {Iterator<? extends GrantedAuthority> it = authResult.getAuthorities().iterator(); switch (it.next().getAuthority()) { case (MyConstants.ROLE_USER): { try { request.getRequestDispatcher("/user/data").forward(request, response); break; } catch (ServletException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }所以我想將我需要的帶有 JSON 數(shù)據(jù)的 rquest 對(duì)象轉(zhuǎn)發(fā)到我的 RestController 端點(diǎn)。這有效。在我的控制器中,我想返回帶有數(shù)據(jù)和 Http 狀態(tài)代碼的 ResponseEntity。@RequestMapping(value="/upload", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity< HttpStatus> upload(@RequestBody String uploadData){ ResponseEntity<String> httpStatus = sendExchangeToRestApi(MediaType.APPLICATION_JSON, uploadData, "http://localhost:8080/upload", HttpMethod.PUT); return new ResponseEntity<String>("Test". HttpStatus.OK);}我用郵遞員測試了這個(gè)。輸出沒問題,所以我在我的身體輸出中得到狀態(tài) 200 和測試。
1 回答

慕村225694
TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊
你應(yīng)該知道的一件事是,每個(gè)微服務(wù)都應(yīng)該有自己的數(shù)據(jù)庫,如果你所有的微服務(wù)共享同一個(gè)數(shù)據(jù)庫,那么數(shù)據(jù)庫將成為你的中心合約,并且總是很難做出改變,因?yàn)槟阌肋h(yuǎn)不知道哪個(gè)微服務(wù)使用什么。
談到RabbitMQ,我個(gè)人認(rèn)為它是有史以來最好的Message-Broker。我建議您擁有一個(gè)隊(duì)列/微服務(wù)和一個(gè) Exchange/微服務(wù)。您可以輕松配置 RabbitMQ 以根據(jù)路由鍵在隊(duì)列之間重定向消息。
希望這有助于最好的敬意
添加回答
舉報(bào)
0/150
提交
取消