_parseEnvironment

Convert 'name' or 'fallback:name' into an Environment.

_parseEnvironment(environment: any)
Parameters
environment (any)

init

Create an unstarted instance of the MDK.

init()

start

Create a started instance of the MDK. This is equivalent to calling init() followed by start() on the resulting instance.

start()

MDK

The MDK API consists of two interfaces: MDK and Session. The MDK interface holds globally scoped APIs and state associated with the microservice. The Session interface holds locally scoped APIs and state. A Session must be used sequentially.

The MDK instance is responsible for communicating with foundational services like discovery and tracing.

There will typically be one MDK instance for the entire process, and one instance of the Session object per thread/channel/request depending on how the MDK is integrated and used within the application framework of choice.

A note on versions: service versions indicate API compatibility, not releases of the underlying code. They should be in the form MAJOR.MINOR, e.g. '2.11'. Major versions indicates incompatibility: '1.0' is incompatible with '2.11'. Minor versions indicate backwards compatibility with new features: a client that wants version '1.1' can talk to version '1.1' and '1.2' but not to version '1.0'.

new MDK()
Static Members
CONTEXT_HEADER
Instance Members
start()
stop()
register(service, version, address)
setDefaultDeadline(seconds)
setDefaultTimeout(seconds)
session()
join(encodedContext)
derive(encodedContext)

Session

A session provides a lightweight sequential context that a microservice can use in the context of any application framework in order to manage its interactions with other microservices. It provides simple APIs for service resolution, distributed tracing, and circuit breakers.

A microservices architecture enables small self contained units of business logic to be implemented by separate teams working on isolated services based on the languages and frameworks best suited for their problem domain.

Any given microservice will contain sequential business logic implemented in a variety of ways depending on the application framework chosen. For example it may be a long running thread, a simple blocking request handler, or a chained series of reactive handlers in an async environment.

For the most part this business logic can be implemented exactly as prescribed by the application framework of choice, however in a microservices architecture, some special care needs to be taken when this business logic interacts with other microservices.

Because microservices are updated with much higher frequency than normal web applications, the interactions between them form key points that require extra care beyond normal web interactions in order to avoid creating a system that is both extremely fragile, unreliable, and opaque.

Realtime service resolution, distributed tracing, and resilience heuristics such as circuit breakers provide the foundational behavior required at these interaction points. These capabilites must be combined with the defensive coding practice of intelligent fallback behavior when remote services are unavailable or misbehaving, in order to build a robust microservice application.

Because of this, a session is expected to be created and made available to all business logic within a given microservice, e.g. on a per request basis, as a thread local, part of a context object, etc depending on the application framework of choice.

new Session()
Instance Members
inject()
externalize()
critical(category, text)
error(category, text)
warn(category, text)
info(category, text)
debug(category, text)
trace(level)
route(service, version, target, targetVersion)
resolve(service, version)
resolve_until(service, version, timeout)
resolve_async(service, version)
start_interaction()
fail_interaction(message)
finish_interaction()
interact(callable)
setDeadline(seconds)
setTimeout(seconds)
getRemainingTime()
getProperty(property)
setProperty(property, value)
hasProperty(property)
getEnvironment()

getDiscoveryFactory

Choose DiscoverySource based on environment variables.

getDiscoveryFactory(env: any)
Parameters
env (any)

getFailurePolicy

Choose FailurePolicy based on environment variables.

getFailurePolicy(runtime: any)
Parameters
runtime (any)

getWSClient

Get a WSClient, unless env variables suggest the user doesn't want one.

getWSClient(runtime: any)
Parameters
runtime (any)

CONTEXT_HEADER

This header is used to propogate shared context for distributed traces.

CONTEXT_HEADER

LoggedMessageId

Information about the message that was just logged.

new LoggedMessageId(traceId: any, causalLevel: any, environment: any, environmentFallback: any)
Parameters
traceId (any)
causalLevel (any)
environment (any)
environmentFallback (any)

traceId

The ID of the trace this message was logged in.

traceId

causalLevel

The causal clock level within the trace.

causalLevel

environment

The operational environment.

environment

environmentFallback

The fallback operational environment.

environmentFallback