bootique / bootique-jetty

Provides Jetty integration with Bootique

Home Page:https://bootique.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebSocket: API to use initiating request MDC

andrus opened this issue · comments

Per #104 we have a new Slf4J MDC management API in Jetty. Let's extend it to websockets, so that each socket session would inherit MDC from the initiating web request. Since websocket operations happen in different threads, we have to establish and clean up the context on every method call of a ws endpoint. Don't see an easy way to intercept that automatically, so going to provide an injectable instance of WebSocketMDCManager that will have to be manually applied as this:

@Inject
WebSocketMDCManager mdc;

@OnMessage
public void onMessage(String m, Session s) {
    mdc.run(s, () -> { /* do something */});
}

MDC data will be captured in the Session "userProperties" map.