Skip to content

need for global state in Arazzo (MayBe?) - Broken workflow in Kafka Sample #1

@nashjain

Description

@nashjain

In the GetUser step

      - kind: openapi
        stepId: GetUser
        operationId: $sourceDescriptions.UserEmailApi.getUserByEmail
        parameters:
          - name: email
            in: query
            value: $inputs.email
        successCriteria:
          - condition: $statusCode == 200
        outputs:
          userId: $response.body#/id #Storing userId for later use
        onFailure:
          - condition: $statusCode == 404
            type: goto
            step: CreateUser
        onSuccess:
          - condition: $statusCode == 200
            goto: WaitForUserAck #Jumping to the WaitForUserAck step

If the user exists, we are storing the userId to be used later in the WaitForUserAck step.

However, in the WaitForUserAck steps:

      - kind: asyncapi
        stepId: WaitForUserAck
        operationId: $sourceDescriptions.EventBus.receiveUserAck
        action: receive
        correlationId: $steps.CreateUser.outputs.userCorrelationId # If we come from GetUser, correlationId won't exist 
        timeout: 10000
        successCriteria:
          - condition: $message.payload.status == "ok"
        outputs:
          userId: $message.payload.userId #Here again we are storing the userId, but we already have the userId from GetUser step

Ideally, from GetUser onSuccess we should go to SendPaymentRequest step since we already have the userId. However, there is a complication. In the SendPaymentRequest step:

      - kind: asyncapi
        stepId: SendPaymentRequest
        operationId: $sourceDescriptions.EventBus.sendPaymentRequest
        dependsOn:
          - $steps.WaitForUserAck # if we come from GetUser step, then we cannot depend on WaitForUserAck step
        action: send
        requestBody:
          contentType: application/json
         # This payload assumes that user was created via CreateUser step and fetched via the  WaitForUserAck step. It completely ignores if the user already existed.
          payload: |
            {
              "userId": "{$steps.WaitForUserAck.outputs.userId}", 
              "productId": "{$inputs.productId}",
              "orderId": "{$inputs.orderId}",
              "amount": "{$inputs.amount}"
            }
        parameters:
          - name: correlationId
            in: header
            value: "{$inputs.orderId}"

Looks like we've a limitation in Arazzo Spec, we need an ability for 2 steps to update some global variable state, which can be then referenced by other steps. In this case, both GetUser and WaitForUserAck step should update userId in some global state, so that subsequent steps can pick the userId from the global state irrespective of which step was executed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions