@@ -193,11 +193,8 @@ module.exports = function ChannelsMiddleware(mwOpts) {
193193 opts . headers . $caller = opts . ctx . service . fullName ;
194194 }
195195
196- if ( opts . ctx . currentChannelName ) {
197- opts . headers . $parentChannelName = opts . ctx . currentChannelName ;
198- }
199- if ( opts . ctx . currentServiceName ) {
200- opts . headers . $parentServiceName = opts . ctx . currentServiceName ;
196+ if ( opts . ctx . channelName ) {
197+ opts . headers . $parentChannelName = opts . ctx . channelName ;
201198 }
202199
203200 // Serialize meta and headers
@@ -295,12 +292,7 @@ module.exports = function ChannelsMiddleware(mwOpts) {
295292 // Wrap the handler with context creating
296293 if ( chan . context ) {
297294 wrappedHandler = ( msg , raw ) => {
298- let parentCtx ,
299- caller ,
300- meta ,
301- ctxHeaders ,
302- parentChannelName ,
303- parentServiceName ;
295+ let parentCtx , caller , meta , ctxHeaders , parentChannelName ;
304296 const headers = adapter . parseMessageHeaders ( raw ) ;
305297 if ( headers ) {
306298 if ( headers . $requestID ) {
@@ -312,7 +304,6 @@ module.exports = function ChannelsMiddleware(mwOpts) {
312304 } ;
313305 caller = headers . $caller ;
314306 parentChannelName = headers . $parentChannelName ;
315- parentServiceName = headers . $parentServiceName ;
316307 }
317308
318309 if ( headers . $meta ) {
@@ -330,20 +321,15 @@ module.exports = function ChannelsMiddleware(mwOpts) {
330321
331322 const ctx = Context . create ( broker , null , msg , {
332323 parentCtx,
333- caller : headers ?. $parentServiceName
334- ? headers . $parentServiceName
335- : caller ,
324+ caller,
336325 meta,
337326 headers : ctxHeaders
338327 } ) ;
339328
340- // attach channelName to context so in the handler we can use it
341- ctx . currentChannelName = chan . name ;
342- ctx . currentServiceName = svc . fullName ;
343- // It's the parent channel name that triggered this event
329+ ctx . channelName = chan . name ;
344330 ctx . parentChannelName = parentChannelName ;
345- ctx . parentServiceName = parentServiceName ;
346331
332+ // Attach current service that has the channel handler to the context
347333 ctx . service = svc ;
348334
349335 return handler2 ( ctx , raw ) ;
0 commit comments