Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 791885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:54:28+00:00 2026-05-14T21:54:28+00:00

I ran into the following problem in dynamically creating topics for our ActiveMQ system:

  • 0

I ran into the following problem in dynamically creating topics for our ActiveMQ system:

I have a number of processes (M_1, …, M_n), where n is not large, typically 5-10. Some of the processes will listen to the output of others, through a message queue; these edges are specified in an XML file, e.g.

<link from="M1" to="M3"</link>
<link from="M2" to="M4"</link>
<link from="M3" to="M4"</link>

etc. The edges are sparse, so there won’t be many of them. I will parse this XML and store this information in an SQL DB, one table for nodes and another for edges.

Now, I need to dynamically create strings of the form

M1.exe --output_topic=T1
M2.exe --output_topic=T2
M3.exe --input_topic=T1 --output_topic=T3
M4.exe --input_topic=T2 --input_topic=T3 

where the tags are sequentially generated. What is the best way to go about querying SQL to obtain these relationships? Are there any tools or other tutorials you can point me to? I’ve never done graps with SQL.

Using SQL is imperative, because we use it for other stuff, too.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:54:28+00:00Added an answer on May 14, 2026 at 9:54 pm

    Ok, here’s my stab at the problem.

    Here’s a sketch of the nodes and edges tables:

    [nodes]
    node : varchar(xx)
    
    [edges]
    outputNode : varchar(xx)
    inputNode : varchar(xx)
    

    Assuming your db has support for CTEs, then a query structured like this will bring together the relationships and concatenate results:

    /* pair output nodes with a topic, assigned sequentially */
    WITH OutputTopics(node, topicNumber) AS (
       SELECT outputNode, ROW_NUMBER() (ORDER BY outputNode) AS topicNumber 
       FROM 
         (SELECT DISTINCT outputNode FROM edges) AS outputNodes
    ), 
    /* pair input nodes to the topic of associated output nodes */
    InputTopicNumbers(inputNode, topicNumber) AS (
       SELECT edges.inputNode, ot.topicNumber FROM edges INNER JOIN
           OutputTopics AS ot ON ot.node=edges.outputNode
    ),
    /* Recursive CTE to concat all topics together */
    InputTopics(inputNode, topics, topicNumber) AS (
          /* The seed for the recursion - all input nodes */
          SELECT inputNode, CAST ('' AS nvarchar(max)), 0 /* max topic handled for node */
          FROM InputTopicNumbers
          GROUP BY inputNode
       UNION ALL /* Add topics that are greater than those processed */
          /* recursively concat topic numbers in ascending order */
          SELECT i.inputNode, CONCAT(c.topics, ' --input-topic=T',i.topicNumber), i.topicNumber
          FROM InputTopics AS c 
          INNER JOIN InputTopicNumbers i ON i.inputNode=c.inputNode
          WHERE i.topicNumber > c.topicNumber
    ),
    /* Bring it all together - append each node with '.exe',
       list the output topic, if present
       Use the recursive CTE to concat all inputTopics */
    NodeCommands(node, exe, input, output) AS (
        SELECT nodes.node,
           CONCAT(nodes.node,'.exe'), 
           CONCAT(' --output_topic=T',ot.topicNumber), /* NULL if no output node */
           it.topics
        FROM nodes
        LEFT OUTER JOIN OutputTopics AS ot ON ot.node=nodes.node
        LEFT OUTER JOIN InputTopics AS it ON it.inputNode=nodes.node
    )
    /* finally our top-level query concatenates the parts to 
       arrive at a single command line */
    SELECT CONCAT(
       exe, 
       ISNULL(input, ''),
       ISNULL(output, '')) 
    FROM NodeCommands ORDER BY node
    

    I’m doing this off the bat, so surely a few syntax errors in there. I hope the comments explain the intent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.