Search code examples
google-cloud-platformgoogle-cloud-functionsmapreducegoogle-cloud-pubsubgoogle-cloud-run

Dynamically Create Cloud Run or Function determined by attribute in pub/sub


I am trying to get a Cloud Run or Cloud Function to start and pull out messages that match its defined ID, for example, if a message with attribute ID 1 is put into the topic, The Cloud Run with ID 1 will take it out, it's important that all messages with attribute 1 go to the same instance.

I understand I could use filters on the subscriptions but I would like to able to easily change the amount of possible ID's, e.g. If I only put messages in the topic with ID's ranging between 0 and 4 then only five instances would be started.Proposed structure diagram

How would I go about creating something like this? Does Pub/Sub support this sort of functionality?

I know I could create X amount of topics and then put each message into its own topic but that seems like a inefficient way of executing this when there is the attribute system.


Solution

  • This was not possible, I had to instead, wait for all data for the desired function to be ready before starting the function, I could not have it continually poll and get the correct data.

    Therefore the best approach was to put the data into a firestore, then when all the data was ready for the next layer to process it, I would put a message in a pub sub that contained a message ID, this message ID would determine the data that this function would process.

    The function would then query the firestore for messages with a property that included the message ID it was given.

    I could not find any other work approaches that would give me the result I desired.