Hi All,
Need some insight on the following scenario :
I am trying to use nodeJS to retrieve Details from KVM ( Dynamic map and values)
Questions:
Note:
KVM policy doesn't support dynamic maps
JS doesn't support calling KVM in Apigee.
I have created a small POC to check if i can retrieve details form KVM
var http = require('http'); var apigee = require('apigee-access'); var svr = http.createServer(function (req, res) { console.log('The deployment mode is ' + apigee.getMode()); // map name will be dynamic var kvm = apigee.getKeyValueMap('KVPMap', 'environment'); // v1 will be dynamic variable in actual code kvm.get('v1', function(err, key_value) { apigee.setVariable(response, 'kvmvalue', key_value); }); res.end(); }); svr.listen(9000, function() { console.log('Node HTTP server is listening'); }); <br />
Looking forward for your response
Thnaks,
Hi
It seems a bit heavy to use a nodejs target in order to retrieve and parse JSON from the KVM. The nodejs target will soon be deprecated in favor of Hosted Targets, and the apigee_access module will likewise be deprecated. We think there are better ways to do things than use the apigee_access module.
Can you help me understand what you mean by this:
KVM policy doesn't support dynamic maps
What does the KVM policy NOT DO, that you would like it to do? Maybe give an example to clarify it for me. I think maybe you want a dynamic MAP NAME. Why do you need that? You have a dynamic key. Why not use the key for the dynamic behavior, and not also require a dynamic map name. Remember the key is composite. You can store thousands of entries in a single map.
Normally what I have seen people do, is retrieve from KVM with a KeyValueMapOperations policy using the Get element. And then parse the resulting JSON and extract the value from the retrieved string into a set of context variables.
This requires 2 policies: a KVM GET and then a "boilerplate" JS policy that can just JSON.parse() the retrieved value, and then walk the JSON hash and set a bunch of context variables, one for each property in the hash. Suppose the stored value is
{"a":1, "b": "xyz", "c": true}
...then the result of the JS policy would be to parse that and set these variables:
myprefix.a | 1 |
myprefix.b | "xyz" |
myprefix.c | true |
And then of course you would need a third policy, or a Condition etc, which would refer to the variables that were extracted by the JS policy.
The KVM GET can of course be parameterized. You can specify a variable or a set of variables to compose the Key you use in retrieval. So that is one element of dynamic behavior; maybe you were not aware of it? Eg,
<Key> <Parameter>prefix</Parameter> <Parameter ref="client_id"/> <Parameter ref="system.time.dayofweek"/> <Parameter>weight</Parameter> </Key>
If you retrieve JSON from the KVM, In the future there will be another option available to you; in the Message Template, you will be able to use a jsonPath() query on the JSON string, similar to a simple variable reference. That would allow you to extract the value of "b" without a JS policy. if json_value_from_KVM holds the JSON string, you could do this:
{jsonPath("$.b",json_value_from_KVM)}
But this isn't yet available.
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 |