Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variables from schema cannot be used in producer #174

Open
Jozef63 opened this issue Aug 18, 2022 · 3 comments
Open

variables from schema cannot be used in producer #174

Jozef63 opened this issue Aug 18, 2022 · 3 comments

Comments

@Jozef63
Copy link

Jozef63 commented Aug 18, 2022

Hello, I am using reactive producer for kafka mock actor as described here in documentation

The variables from consumer are not present in producer

here is a dummy code for actors configuration that I am using :

      - name: dummy-mock
        consume:
          queue: REQUEST
          capture: 10
          schema: "@value/Request.json"
        produce:
          queue: RESPONSE
          key: "can reference as {{consumed.value}}"
          value: "@value/Response.json"

here is Request.json:

{
  "someId": "{{someId}}",
  "code": "{{code}}"
}

here is Response.json:

{
  "someId": "{{someId}}",
  "code": "{{code}}",
  "someOtherField": "someValue"
}

after producing a message like:

{
  "someId": "someValue",
  "code": "someValue"
}

the consumer receives message, producer produces a message too but I get following warning:

[2022-08-18 12:41:47,241 root WARNING] Handlebars: Could not find variable 'someId'

and the produced message is without filled values :

{
  "someId": "{{someId}}",
  "code": "{{code}}",
  "someOtherField": "someValue"
}
@undera
Copy link
Contributor

undera commented Aug 18, 2022

The confusion is probably around the way you reference the consumed message. Pay attention to consumed. prefix of values referenced. In your example, you have the just someId referenced.
Looks like you would need to properly reference consumed. message, and also apply some additional processing to get exact pieces of consumed JSON.

Below is my speculative improvement of Response.json:

{
  "someId": "{{consumed.value | fromjson| jsonpath '$.someId'}}",
  // and so on
}```

Haven't tried it myself, though. Let me know if it helps

@Jozef63
Copy link
Author

Jozef63 commented Aug 19, 2022

Hi, thank you for your answer, but still it doesn't work.

Handlebars: Error at character 38 of line 7 near |

Seems like | character is invalid ? Is there some documentation around fromjson jsonpath and this | character that you are using in your speculative improvement :) ?

@undera
Copy link
Contributor

undera commented Aug 19, 2022

My bad. Can you look at this PR? #167
There is an example of expression there, looks exactly applying to your case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants