用于微服务的客户端服务发现组件。

configuration-layer的Python项目详细描述


微服务的初始配置层

#光盘机

这项服务在他很小的时候。不要在生产中使用或者如果您愿意,请注意您将使用一段可能 很快而且非常经常地改变或改进(不一定按这个顺序)。你被警告了! 此服务至少需要另一个服务来监听一些卡夫卡主题。

服务说明

此服务已开发为用作基于多层微服务的基础结构的一部分。 它为服务提供一层要使用的功能,以便请求启动服务所需的配置设置。 它使用kafka作为消息传递平台,以便在服务之间交换消息。 为了使用它,它需要一个充当service registry的服务,该服务接收请求并发送回响应。 当在不可中断模式下接收到配置时,可以执行加法功能。当我们希望由于给定服务的配置更新而添加响应行为时,这很方便

如何将其添加到您的微服务中

fromconfiguration_layer.service_setup.configuration_requestimportConfigurationSeekerfromconfiguration_layer.utils.configuration_validationimportvalidate_service_configurationimportconfiguration_layer.helpers.producer_messagesasmessageimportsys,osimportdatetimefrommessaging_middleware.utils.loggerimportLoggerdefcheck_configuration_directory():service_configuration_directory=os.environ.get('service_configuration_directory','configuration')ifos.path.isdir(service_configuration_directory):returnos.getcwd()+service_configuration_directoryelse:returnFalsedefseeker_request(**kwargs):seeker=ConfigurationSeeker(consumer_topic='tcsetconf',producer_topic='tcgetconf',bootstrap_servers="your broker here",schema_registry='your schema registry here',message={"cmd":"get_conf","auth":"ASC","service_name":"myservicename"},key_schema={"service_name":"myservicename"},service_name='myservicename',service_configuration_directory=os.environ.get('service_configuration_directory','configuration'),breakable=kwargs.get('breakable',1),set=kwargs.get('set',0),function_to_run=kwargs.get('function_to_run',None))seeker.start()seeker.join()if__name__=="__main__":ifnotcheck_configuration_directory():sys.exit()logger=Logger()seeker_request()ifvalidate_service_configuration():logger.logmsg('info',"==Configuration Completed==")else:message_to_produce=message.operation_result(service_name="myservicename",last_operation='setconf',timestamp=datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%dT%H:%M:%S%z'),operation_result=message.const_values()['CONFIGURATION_FILE_VALIDATION_ERROR'],error_description='')logger.produce_msg(message_to_produce)logger.logmsg('error',"==CONFIGURATION_FILE_VALIDATION_ERROR==")sys.exit()

SSL配置

如果要使用ssl等安全协议,必须应用以下更改

fromconfiguration_layer.service_setup.configuration_requestimportConfigurationSeekerfromconfiguration_layer.utils.configuration_validationimportvalidate_service_configurationimportconfiguration_layer.helpers.producer_messagesasmessageimportsys,osimportdatetimefrommessaging_middleware.utils.loggerimportLoggerdefcheck_configuration_directory():service_configuration_directory=os.environ.get('service_configuration_directory','configuration')ifos.path.isdir(service_configuration_directory):returnos.getcwd()+service_configuration_directoryelse:returnFalsedefseeker_request(**kwargs):seeker=ConfigurationSeeker(consumer_topic='tcsetconf',producer_topic='tcgetconf',bootstrap_servers="your broker here",schema_registry='your schema registry here',message={"cmd":"get_conf","auth":"ASC","service_name":"myservicename"},key_schema={"service_name":"myservicename"},service_name='myservicename',service_configuration_directory=os.environ.get('service_configuration_directory','configuration'),breakable=kwargs.get('breakable',1),set=kwargs.get('set',0),security_protocol='ssl',function_to_run=kwargs.get('function_to_run',None))seeker.start()seeker.join()if__name__=="__main__":ifnotcheck_configuration_directory():sys.exit()logger=Logger()seeker_request()ifvalidate_service_configuration(ssl=1):logger.logmsg('info',"==Configuration Completed==")else:message_to_produce=message.operation_result(service_name="myservicename",last_operation='setconf',timestamp=datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%dT%H:%M:%S%z'),operation_result=message.const_values()['CONFIGURATION_FILE_VALIDATION_ERROR'],error_description='')logger.produce_msg(message_to_produce)logger.logmsg('error',"==CONFIGURATION_FILE_VALIDATION_ERROR==")sys.exit()

融合卡夫卡主题:

服务将消息发送到预定义(硬编码ATM)主题,该主题具有以下架构注册表

tcServicesMonitor值架构消息

{"schema":"{\"type\":\"record\",\"name\":\"key\",\"namespace\":\"example.avro\",\"fields\":[{\"name\": \"service_name\", \"type\": \"string\",\"default\": \"empty\"},{\"name\": \"last_operation\", \"type\": \"string\",\"default\": \"empty\"},{\"name\": \"timestamp\", \"type\": \"string\",\"default\": \"empty\"},{\"name\": \"operation_result\", \"type\":\"string\" },{\"name\": \"operation_description\", \"type\":\"string\" ,\"default\": \"empty\"},{\"name\": \"error_description\", \"type\":\"string\" ,\"default\": \"empty\"}]}"}
{"type":"record","name":"key","namespace":"example.avro","fields":[{"name":"service_name","type":"string","default":"empty"},{"name":"last_operation","type":"string","default":"empty"},{"name":"timestamp","type":"string","default":"empty"},{"name":"operation_result","type":"string"},{"name":"operation_description","type":"string"}]}

tcServicesMonitor键架构消息

{"type":"record","name":"key","namespace":"example.avro","fields":[{"name":"service_name","type":"string","default":"empty"}]}

消息有效负载配置的外观示例

请求

{"topic":"tcgetconf","value":{"cmd":"get_conf","auth":"ASC","service_name":"myservicename"}}

回复

{"service_name":"myservicename","start_environment":"staging","datacentre":"","external_rest_services":{},"persistence_conf":{},"credentials":{}}

#更改日志

  • 1.0.14条 改进了传入/传出消息的处理。添加了事件处理程序

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
两个给定LinkedList的java交集   将Java菜单栏操作swing到类   特别是正则表达式的Java原始字符串。多行字符串   java maven2:如何获取/设置本地服务器的位置。jar缓存?   在Java中,找到单个点X最接近arraylist中哪对相邻点的最佳方法是什么?   java如何解决forloop中的Sonaqube抱怨问题?   参数类型的java AspectJ切入点   在基于Java的spring配置层次结构中重写bean   Appium\MAC OS\Android\Java组织。openqa。硒。SessionNotCreatedException   java数组对象列表(通过intent)   java模拟方法中的文件、filewriter和csvwriter,以进行单元测试引发NullPointerException   java中如何在不定义大小的情况下获取N个元素的输入数组