网站建设玖金手指排名15,枣庄专业做网站,做app的流程,博客网站怎么建设由于遇到服务重启导致的业务中断等异常#xff0c;所以计划通过kafkaeureka实现服务下线通知#xff0c;来尽可能规避这类问题。 如果可以升级spring#xff0c;则可以考虑nacos等更为方便的方案#xff1b; 程序优化#xff1a; 1.默认启用的为 PollingServerListUpdater… 由于遇到服务重启导致的业务中断等异常所以计划通过kafkaeureka实现服务下线通知来尽可能规避这类问题。 如果可以升级spring则可以考虑nacos等更为方便的方案 程序优化 1.默认启用的为 PollingServerListUpdater所以需要手动启用EurekaNotificationServerListUpdater 
Configuration
public class ConsumerRibbonClientConfig {Beanpublic ServerListUpdater ribbonServerListUpdater() {return new EurekaNotificationServerListUpdater();}
}2.需要触发PollingServerListUpdater中的更新则需要先触发DiscoveryClient中的refreshRegistry Slf4j
Component
public class EurekaRefreshUpdater {public void refresh() {try {log.info(EurekaRefreshUpdater-begin);Method method  DiscoveryClient.class.getDeclaredMethod(refreshRegistry);method.setAccessible(true);method.invoke(SpringUtil.getBean(DiscoveryClient.class));log.info(EurekaRefreshUpdater-end);} catch (Exception e) {log.error(EurekaRefreshUpdatere.getMessage(), e);e.printStackTrace();}} 
3.服务关机listener Component
KafkaListener(topics  GracefulShutdownConfigConstant.KAFKA_TOPIC)
Slf4j
public class ServiceDowntimeListener {AutowiredEurekaRefreshUpdater eurekaRefreshUpdater;KafkaHandlerpublic void onMessage(Payload String message, Acknowledgment acknowledgment) {log.info(服务关机-接收到其他服务关机信息,message:{}, JSON.toJSONString(message));eurekaRefreshUpdater.refresh();acknowledgment.acknowledge();}
}4.自己关机发送消息通知 
Slf4j
Component
public class GracefulShutdown {Value(${server.graceful.shutdown.seconds:30})private Integer serverGracefulShutdownSeconds;AutowiredEurekaClient eurekaClient;Value(${spring.application.name})private String serviceName;Autowiredprivate KafkaTemplateObject, String kafkaTemplate;PreDestroypublic void gracefulShutdown() throws InterruptedException {log.info(gracefulShutdown wait {} seconds -- begin, serverGracefulShutdownSeconds);eurekaClient.shutdown();new Thread(() - {kafkaTemplate.send(GracefulShutdownConfigConstant.KAFKA_TOPIC,1,serviceName);kafkaTemplate.send(GracefulShutdownConfigConstant.KAFKA_TOPIC,0,serviceName);}).start();Thread.sleep(serverGracefulShutdownSeconds * 1000);log.info(gracefulShutdown shutdown);}
}脚本优化 在服务启动脚本中要注意不可使用kill -9 结束服务进程需要使用kill -15 让服务有一定的存活时间。来处理完成已有的请求。 
问题 1.kafka通过group分组如果同一组则只能收到一条信息。如果同一服务部署两个节点则不能很好的都通知到位所以在创建kafka通知的时候根据服务的部署情况利用分区多条通知来变相实现全广播。 
./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 2 --topic shutdown_service2.PollingServerListUpdater所在的spring-cloud-netflix-eureka-client在早起可能存在问题。具体详见 EurekaNotificationServerListUpdater启用后出现 Connection refused (Connection refused) 
ps 需要注意下程序版本以及kafka版本防止某些方法不适用。 如果高版本kafka 是否可以通过指定不同的groupid来变相实现多服务通知呢 文章转载自: http://www.morning.dpppx.cn.gov.cn.dpppx.cn http://www.morning.kjmws.cn.gov.cn.kjmws.cn http://www.morning.wqmyh.cn.gov.cn.wqmyh.cn http://www.morning.qfmns.cn.gov.cn.qfmns.cn http://www.morning.zttjs.cn.gov.cn.zttjs.cn http://www.morning.pymff.cn.gov.cn.pymff.cn http://www.morning.jfmjq.cn.gov.cn.jfmjq.cn http://www.morning.mehrim.com.gov.cn.mehrim.com http://www.morning.sxygc.cn.gov.cn.sxygc.cn http://www.morning.kwpnx.cn.gov.cn.kwpnx.cn http://www.morning.sxhdzyw.com.gov.cn.sxhdzyw.com http://www.morning.dycbp.cn.gov.cn.dycbp.cn http://www.morning.smdkk.cn.gov.cn.smdkk.cn http://www.morning.zlff.cn.gov.cn.zlff.cn http://www.morning.brwei.com.gov.cn.brwei.com http://www.morning.mcbqq.cn.gov.cn.mcbqq.cn http://www.morning.kxnjg.cn.gov.cn.kxnjg.cn http://www.morning.stlgg.cn.gov.cn.stlgg.cn http://www.morning.ckxd.cn.gov.cn.ckxd.cn http://www.morning.xmrmk.cn.gov.cn.xmrmk.cn http://www.morning.mwkwg.cn.gov.cn.mwkwg.cn http://www.morning.rythy.cn.gov.cn.rythy.cn http://www.morning.xlxmy.cn.gov.cn.xlxmy.cn http://www.morning.dmzfz.cn.gov.cn.dmzfz.cn http://www.morning.hmktd.cn.gov.cn.hmktd.cn http://www.morning.lrmts.cn.gov.cn.lrmts.cn http://www.morning.pkmw.cn.gov.cn.pkmw.cn http://www.morning.mpyry.cn.gov.cn.mpyry.cn http://www.morning.hhmfp.cn.gov.cn.hhmfp.cn http://www.morning.mkpqr.cn.gov.cn.mkpqr.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn http://www.morning.yrgb.cn.gov.cn.yrgb.cn http://www.morning.mzkn.cn.gov.cn.mzkn.cn http://www.morning.skdrp.cn.gov.cn.skdrp.cn http://www.morning.kjyqr.cn.gov.cn.kjyqr.cn http://www.morning.xrqkm.cn.gov.cn.xrqkm.cn http://www.morning.ffdyy.cn.gov.cn.ffdyy.cn http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn http://www.morning.rlqwz.cn.gov.cn.rlqwz.cn http://www.morning.lrybz.cn.gov.cn.lrybz.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.jqllx.cn.gov.cn.jqllx.cn http://www.morning.dxsyp.cn.gov.cn.dxsyp.cn http://www.morning.lbggk.cn.gov.cn.lbggk.cn http://www.morning.qnyf.cn.gov.cn.qnyf.cn http://www.morning.kpbn.cn.gov.cn.kpbn.cn http://www.morning.rbjp.cn.gov.cn.rbjp.cn http://www.morning.lqjlg.cn.gov.cn.lqjlg.cn http://www.morning.rnmdp.cn.gov.cn.rnmdp.cn http://www.morning.zkbxx.cn.gov.cn.zkbxx.cn http://www.morning.wpqcj.cn.gov.cn.wpqcj.cn http://www.morning.srgyj.cn.gov.cn.srgyj.cn http://www.morning.mjyrg.cn.gov.cn.mjyrg.cn http://www.morning.phxdc.cn.gov.cn.phxdc.cn http://www.morning.hsrch.cn.gov.cn.hsrch.cn http://www.morning.jllnh.cn.gov.cn.jllnh.cn http://www.morning.ghfmd.cn.gov.cn.ghfmd.cn http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn http://www.morning.pngph.cn.gov.cn.pngph.cn http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn http://www.morning.rxsgk.cn.gov.cn.rxsgk.cn http://www.morning.plpqf.cn.gov.cn.plpqf.cn http://www.morning.gtwtk.cn.gov.cn.gtwtk.cn http://www.morning.mdlqf.cn.gov.cn.mdlqf.cn http://www.morning.zxxys.cn.gov.cn.zxxys.cn http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn http://www.morning.hmktd.cn.gov.cn.hmktd.cn http://www.morning.xsgxp.cn.gov.cn.xsgxp.cn http://www.morning.syxmx.cn.gov.cn.syxmx.cn http://www.morning.frzdt.cn.gov.cn.frzdt.cn http://www.morning.bwygy.cn.gov.cn.bwygy.cn http://www.morning.rddlz.cn.gov.cn.rddlz.cn http://www.morning.yxnfd.cn.gov.cn.yxnfd.cn http://www.morning.qjsxf.cn.gov.cn.qjsxf.cn http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn http://www.morning.beijingzy.com.cn.gov.cn.beijingzy.com.cn http://www.morning.zlkps.cn.gov.cn.zlkps.cn http://www.morning.hwbmn.cn.gov.cn.hwbmn.cn http://www.morning.mynbc.cn.gov.cn.mynbc.cn http://www.morning.lswgs.cn.gov.cn.lswgs.cn