java - Spring-data-jpa 剛保存的信息查找不到
問題描述
1 后臺結構后臺的結構是 SpringMVC, Spring, jpa(HibernateJpaDialect),DataSource(c3p0), Mysql(InnoBDB), transactionManager(JpaTransactionManager)。
2 問題環境@Transactional(value = 'transactionManager', isolation = Isolation.READ_UNCOMMITTED) public Object addScenicSpot(int tourGuideID, String jsonStr) {Djd_js entity = new Djd_js();try{ _setEntity(entity, jsonStr); entity.setDaoyouID(tourGuideID); jdjsDao.save(entity); int spotId = entity.getId(); //添加信息到消息隊列中try { Sender sender = new SenderImpl(); sender.getGPSFromBaiduAPI('jdjs', spotId, entity.getDizhi());} catch (InterruptedException e) { return false;} return spotId;}catch (Exception e){ return false;} }
以上是保存的部分,并把得到的 ID 發送到消息隊列中,下邊是消息隊列的處理部分
public boolean updateLngAndLat(MessageVo messageVo) {System.out.println('CreateTime--------'+messageVo.getCreateDate());System.out.println('Address--------'+messageVo.getContent());System.out.println('Id--------'+messageVo.getId());Djd_js entity = jdjsDao.findOne(messageVo.getId());System.out.println('entity-Address--------'+entity.getDizhi());、、運行到這里就直接卡住了,如果注釋掉查詢,其他的調用皆正常。Map<String, Object> result = LngAndLatUtil.getLngAndLat(((MessageVo) messageVo).getContent());System.out.println('result--------'+(int)result.get('result'));if (1 == (int)result.get('result')){ entity.setJingdu(Double.valueOf(result.get('lng').toString())); entity.setWeidu(Double.valueOf(result.get('lat').toString())); System.out.println('message-------------------------------'+'lng:'+Double.valueOf(result.get('lng').toString())+', lat:'+Double.valueOf(result.get('lat').toString())); jdjsDao.updateLngAndLatBySenciSpotID(messageVo.getId(), (Double) result.get('lng'), (Double) result.get('lat'));}else { System.out.println('message-------------------------------False');}return false; }3 問題描述
前端調用 addScenicSpot() 方法,會將信息保存到數據庫中,然后將保存之后的數據控中的ID發送到消息隊列中,然后訂閱者處理隊列中的信息,根據 ID 查詢到剛保存的信息,然后調用外部接口查詢到經緯度,并將得到的經緯度存儲到數據庫中。現在的問題是,保存信息正常,但是到了訂閱者處理這邊,根據得到的 ID 查找不到保存的信息。
4 猜測問題所在產生bug的原因是spring事務提交晚于消息隊列的生產消息,導致消息隊列消費消息時獲取到的數據不正確,靈感來自于這里:http://www.cnblogs.com/taocon...
問題解答
回答1:同步調用,改為異步調用?
@AsyncgetGPSFromBaiduAPI
回答2:已經解決了問題了,應用的這里的方法:http://www.cnblogs.com/taocon...
相關文章:
1. spring-mvc - spring-session-redis HttpSessionListener失效2. IOS app應用軟件的id號怎么查詢?比如百度貼吧的app-id=4779278133. html - angular項目中如何讓外鏈網頁在本項目中展示?4. 淺談Vue使用Cascader級聯選擇器數據回顯中的坑5. 運行python程序時出現“應用程序發生異常”的內存錯誤?6. java中double類型轉換為String類型?7. javascript - 最近用echarts做統計圖時遇到兩個問題!!8. javascript - 在 model里定義的 引用表模型時,model為undefined。9. mysql - 查詢 修改數據庫優化問題吧10. linux - 將java項目部署在vbox的centos系統上,無法實現外網訪問到java項目

網公網安備