Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IDEA] router.routeMessage should populate sourceMap "sourceChannelID" like a channel writer destination #5293

Open
pacmano1 opened this issue Jul 18, 2022 · 2 comments
Labels
enhancement New feature or request Internal-Issue-Created An issue has been created in NextGen's internal issue tracker RS-9940 triaged

Comments

@pacmano1
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
When using router.route, unless you manually build the source map, the destination channel does not indicate on a message what channel sent the message. A channel writer does automatically add a sourceMap entry

Describe your use case
I need this feature so I can accomplish:

  1. controlling in a destaintion channel what channel(s) are allowed to send it it
  2. answering questions like "what channel sent me this message"

Describe the solution you'd like
For the router.route, automaitcally add the sender channel ID (and name) to the sourceMap.

Describe alternatives you've considered
Obviously I can build that sourceMap, but it should be passive.

Additional context
image

@pacmano1 pacmano1 added the enhancement New feature or request label Jul 18, 2022
@pacmano1 pacmano1 changed the title [IDEA] router.routeMessage should populate sourceMap like a channel writer destination does (i.e w/source channelID) [IDEA] router.routeMessage should populate sourceMap "sourceChannelID" like a channel writer destination Jul 18, 2022
@MichaelLeeHobbs
Copy link

MichaelLeeHobbs commented Nov 29, 2022

/**
 * Route a JSON message to channel by channel id and include the metadata for tracking message flow
 * @param {string} cid
 * @param {Object} json
 */
const routeJsonMsg = (cid, json) => {
  if (!json.metadata) {
    json.metadata = {}
    var sourceChannelIds = sourceMap.get('sourceChannelIds') || sourceMap.get('sourceChannelId')
    var sourceMessageIds = sourceMap.get('sourceMessageIds') || sourceMap.get('sourceMessageId')
    if (sourceChannelIds && sourceMessageIds) {
      json.metadata.sourceChannelIds = sourceChannelIds.toArray ? sourceChannelIds.toArray() : [sourceChannelIds]
      json.metadata.sourceMessageIds = sourceMessageIds.toArray ? sourceMessageIds.toArray() : [sourceMessageIds]
      json.metadata.sourceChannelNames = json.metadata.sourceChannelIds.map(id => ChannelUtil.getChannelName(id))
    } else {
      json.metadata.sourceChannelIds = []
      json.metadata.sourceMessageIds = []
      json.metadata.sourceChannelNames = []
    }
  }
  json.metadata.channelId = channelId
  json.metadata.channelName = channelName
  json.metadata.messageId = connectorMessage.getMessageId()
  json.metadata.errorMessage = json.errorMessage || ''
  json.metadata.errorStack = json.errorStack || ''

  json.metadata.sourceChannelIds.push(channelId)
  json.metadata.sourceMessageIds.push(json.metadata.messageId)
  json.metadata.sourceChannelNames.push(channelName)
  router.routeMessageByChannelId(cid, JSON.stringify(json, null, 2))
}

/* globals router, connectorMessage, channelId, channelName, sourceMap, ChannelUtil, */

@anibal2j
Copy link

anibal2j commented Jan 2, 2023

This is exactly the same thing I'm looking for.

@lmillergithub lmillergithub added triaged Internal-Issue-Created An issue has been created in NextGen's internal issue tracker RS-9940 labels Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Internal-Issue-Created An issue has been created in NextGen's internal issue tracker RS-9940 triaged
Projects
None yet
Development

No branches or pull requests

4 participants