Azure durable functions Activity and CosmosDBInput binding usage

RK 20 Reputation points
2024-06-24T14:32:13.37+00:00

I am using azure durable functions where in from kafka trigger we invoke and orchestrator function which triggers various activities.

With in trigger, we store the message with in cosmos db. However we want to further enrich the stored message with in various activities (based on defined business logic).

Questiosns:

  1. Can i use CosmosDBInput annotation with activity? I cant find any such example and not getting enough documentation that says its supported.
  2. If I can use, how do i frame my query based on the id which is present with in passed to activity function.
  3. Is there any other way, I can directly connect to cosmos db within activity function with using annotations.

Below is the sample code that i am sharing and higlighting my doubts on above point 2 and 3 with ??? sign.

@FunctionName("MessageProcessOrchestrator")

public String messageProcessOrchestrator(

        @DurableOrchestrationTrigger(name = "taskOrchestrationContext") TaskOrchestrationContext ctx,

        ExecutionContext context) {

    Logger log = context.getLogger();

    Event incomingMessage = ctx.getInput(Event.class);

    try{

        ctx.callActivity("ActivityFunction1", incomingMessage, String.class).await() ;

        ctx.callActivity("ActivityFunction2", incomingMessage, String.class).await();

        ctx.callActivity("ActivityFunction3", incomingMessage, String.class).await();

        ctx.callActivity("ActivityFunction4", incomingMessage, String.class).await();

        return "SUCCESS";

    }catch(TaskFailedException e){

        if (!ctx.getIsReplaying()) log.info("Error in orchestrating one of the activity :"+ e.getMessage());

        ctx.callActivity("LogError",incomingMessage, String.class);

        return "FAILED : "+e.getMessage();           

    }

}

@FunctionName("ActivityFunction1")

public String activityFunction1(@DurableActivityTrigger(name = "incomingMessage") Event name, 

@CosmosDBInput(name = "cosmosInput",

connection ="CosmosConStr",

databaseName = "cosmos-db-sql",

containerName = "container",

id="{????? or name.getId() ????? }") Optional
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,598 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RK 20 Reputation points
    2024-06-25T06:50:29.7+00:00

    Managed to resolve it by adding azure sdk.