0
0
Microservicessystem_design~10 mins

Config server pattern in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the central configuration server URL.

Microservices
configServerUrl = "http://[1]:8888"
Drag options to blanks, or click blank then click option'
Adatabase
Blocalhost
Cconfig-server
Dservice-registry
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'localhost' instead of the config server name.
Confusing the config server with the service registry.
2fill in blank
medium

Complete the code to fetch configuration from the config server using HTTP GET.

Microservices
response = httpClient.get(f"http://config-server:8888/[1]/default")
Drag options to blanks, or click blank then click option'
Aservice-name
Benvironment
Cconfig
Dapplication
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'service-name' which is not the standard path segment.
Using 'environment' which is usually a separate path segment.
3fill in blank
hard

Fix the error in the config client code to reload configuration on startup.

Microservices
def load_config():
    config = fetch_config_from_server()
    if config is None:
        raise [1]("Config not found")
    return config
Drag options to blanks, or click blank then click option'
ARuntimeError
BValueError
CConfigError
DKeyError
Attempts:
3 left
💡 Hint
Common Mistakes
Using ValueError which is for invalid values, not missing config.
Using KeyError which is for missing dictionary keys.
4fill in blank
hard

Fill both blanks to complete the config server's response handling code.

Microservices
if response.status_code == 200:
    config_data = response.[1]()
else:
    log.error("Failed to fetch config: " + response.[2])
Drag options to blanks, or click blank then click option'
Ajson
Btext
Ccontent
Dstatus_code
Attempts:
3 left
💡 Hint
Common Mistakes
Using content which returns bytes, not parsed data.
Using status_code which is an integer, not a message.
5fill in blank
hard

Fill all three blanks to complete the microservice config client initialization code.

Microservices
class ConfigClient:
    def __init__(self, [1]):
        self.server_url = [2]
        self.config = self.[3]()

    def fetch_config(self):
        # fetch config logic here
        pass
Drag options to blanks, or click blank then click option'
Aserver_url
Bload_config
Cconfig_server_url
Dfetch_config
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing parameter and attribute names.
Calling 'fetch_config' instead of 'load_config' in constructor.