Skip to content

远程上下文设计 #2

@mengqiang81

Description

@mengqiang81

目前 ServiceContext 会保留 http 协议 header 中所有以 Service-Context 为前缀的 key, 并一直传递下去, 比如 Service-Context-CallId, Service-Context-App 等. 而其他前缀的 header, 在向后调用时会被忽略掉无法透传.

而 ServiceContext 本身继承了 Hashmap, 所以要获取上下文的话, 可以调用 serviceContext.get('Service-Context-App')这样的方法, 设置和修改也可以使用 put 方法.
但是如果 key 不是已 Service-Context 为前缀的话, 透传就会出问题, 会被忽略掉.

现在的问题是, ServiceContext 的结构设计. 我希望业务方可以灵活的设置和修改某一个 key, 同时对 httpheader 友好.

现在有两种方案,

  1. 目前所采用的, 以 key 的前缀为判断依据. {"Service-Context-App":{},"Service-Context-CallId":{}},缺点是业务方需要按约定 get,put
  2. 统一用一个 key {"Service-Context":{"callId":{},"app":{}}}, 缺点是 get,put 方法需要特殊去实现, 也不符合 http 协议header 的惯例用法, 优点是对 key 不需要根据 http 协议特殊要求总长度不超就行

我个人倾向第一种

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions