我目前正在開發一個 Spring Boot 應用程序。我為 httpBasic 身份驗證實現了 Spring Boot 安全性。身份驗證成功后,我的自定義過濾器方法會被調用。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 數據的 rquest 對象轉發到我的 RestController 端點。這有效。在我的控制器中,我想返回帶有數據和 Http 狀態代碼的 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);}我用郵遞員測試了這個。輸出沒問題,所以我在我的身體輸出中得到狀態 200 和測試。
1 回答

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