这是学习的第六篇文章,先初步拆分本系统为四个服务,还没有进行服务治理等,只是简单的业务拆分,为下一步做准备。

天气数据采集微服务
这个微服务专门提供数据采集和定时更新功能,将数据存储在redis中。

该服务的核心service中的方法是:syncDataByCityId,就是根据cityId来将数据同步进redis。
代码:https://github.com/sunweiguo/swgBook-for-spring-cloud/tree/master/spring-cloud-weather-action/06/msa-weather-collection-server
天气数据API
这个服务专门来提供天气数据的查询功能。
将前端页面以及定时、城市相关的代码全部剔除。只留下两个API:
1 2 3
| WeatherResponse getDataByCityId(String cityId);
WeatherResponse getDataByCityName(String cityName);
|
代码:https://github.com/sunweiguo/swgBook-for-spring-cloud/tree/master/spring-cloud-weather-action/06/msa-weather-data-server
天气预报微服务
本服务的主要功能为:用户通过浏览器来访问,可以返回一个天气预报的界面。
就将redis和定时任务相关的都删掉。我们只需要一个接口:
1
| Weather getDataByCityId(String cityId);
|
因为展示数据需要用到城市信息,但是此时还没有,所以需要自己去模拟一些数据去显示。
代码:https://github.com/sunweiguo/swgBook-for-spring-cloud/tree/master/spring-cloud-weather-action/06/msa-weather-report-server
城市数据API
本服务只提供城市列表数据功能。
1
| List<City> listCity() throws Exception;
|
有的需要填充一些假数据之后,都可以独立运行。
代码:https://github.com/sunweiguo/swgBook-for-spring-cloud/tree/master/spring-cloud-weather-action/06/msa-weather-city-server