Client subscribe all / dynamic Topic Id

I have seen 3 old posts on this topic, but none have been updated with a solution. Rather than resurrect the old posts I figured I’d raise the question again:

The task.topicName can be extracted from the task object, so it would be trivial to broker the tasks on the client side. The question is how to subscribe to all topics?

{ activityId: 'Activity_003ssv4',
  activityInstanceId: 'Activity_003ssv4:85246a99-0fb7-11eb-ba67-0242ac110002',
  errorMessage: null,
  errorDetails: null,
  executionId: '85244388-0fb7-11eb-ba67-0242ac110002',
  id: '8524b8ba-0fb7-11eb-ba67-0242ac110002',
  lockExpirationTime: '2020-10-16T13:58:15.344+0000',
  processDefinitionId: 'payment-retrieval:5:25f9641a-0f85-11eb-96c3-0242ac110002',
  processDefinitionKey: 'payment-retrieval',
  processDefinitionVersionTag: null,
  processInstanceId: '7ab50f5a-0fb7-11eb-ba67-0242ac110002',
  retries: null,
  suspended: false,
  workerId: 'some-random-id',
  topicName: 'charge-card',
  tenantId: null,
  variables:
   Variables {
     getTyped: [Function],
     get: [Function],
     getAll: [Function],
     getAllTyped: [Function],
     getDirtyVariables: [Function] },
  priority: 0,
  businessKey: null,
  extensionProperties: {} }

just an FYI - for those who don’t know how to subscribe to multiple known topics:

Hi @dcolley
Welcome to the forum.

I’m wondering if you could let me know the use case you have in mind for a worker subscribing to all topics?

Hi @Niall, I am looking at options for deploying workers (faas/serverless)

I published a pattern ^above^ where a client can subscribe to multiple known topics.

I am also looking for a pattern where a worker can broker (sub-contract?) work down the line. We have a number of solutions utilising pub/sub, and I think this might be an option to plug into that eco-system.

I can already do pub/sub by using the same topicName in all my actions and subscribing a single worker, and then routing on another field - e.g. activityId for the MQTT queue name.

The challenge would then be to correlate and complete the task when that [very] remote worker signals [ok | nok].

When i want to subscribe to more than one topic at a time I add more than one subscription to the client.
Is this something you’ve investigated?

const { Client, logger } = require("camunda-external-task-client-js");
const { Variables } = require("camunda-external-task-client-js");

// configuration for the Client:
// - ‘baseUrl’: url to the Process Engine
// - ‘logger’: utility to automatically log important events
// - ‘asyncResponseTimeout’: long polling timeout (then a new request will be issued)
const config = { baseUrl: "http://localhost:8080/engine-rest", use: logger };

// create a Client instance with custom configuration
const client = new Client(config);

// susbscribe to the topic: ‘charge-card’
client.subscribe("TopicOne", async function({ task, taskService }) {
// Put your business logic here

// Complete the task
await taskService.complete(task,processVariables);
});

// susbscribe to the topic: ‘charge-card’
client.subscribe("TopicTwo", async function({ task, taskService }) {
// Put your business logic here
// Complete the task
await taskService.complete(task,processVariables);
});

We have already used this pattern - ref. my previous post. It requires the subscriber to know the topicId.