variables from schema cannot be used in producer
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"
}
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
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 :) ?
My bad. Can you look at this PR? https://github.com/up9inc/mockintosh/pull/167 There is an example of expression there, looks exactly applying to your case