Hi,
I registered a new service in my vcloud api. When i request a get on this service url, it send an amqp message to my exchange.
I created a policy on my vCO that check messages and triggered a worflow.
My workflow excecute an action, and then i want to reply back to my vcd, but i can't figure out how.
Here is the scripting of my Scriptable Task in my workflow who is in charge to send a reply :
Headers and properties are sent by my policy
One of the problem is that when i consult log, i can see all the message, with headers and properties, but when i receive amqp message on amqp queue, there are no headers and no properties...
Is someone know how to send an amqp message with custom headers and properties ?
Here is a code sample
var msg = broker.retrieveMessage(messageTrigger);
if (msg != null) {
body = msg.bodyAsText;
properties = msg.properties;
headers = msg.headers;
replyToExchange = headers.get("replyToExchange");
var correlationId = properties.get("correlation_id");
var replyTo = properties.get("reply_to");
// Convert the JSON script to a javascript object
var messageBodyObject = eval(body);
var httpMessage = messageBodyObject[0];
//Modify the request and body property
httpMessage.request = false;
httpMessage.body = "SGVsbG8gQVBJIQ=="; // Sending "Hello API"
httpMessage.statusCode = 200;
// Converting javascript object back to JSON
var json =
System.getModule("com.vmware.web.webview").objectToJson(httpMessage);
var amqpMessage = new AMQPMessage();
var prop = new Properties();
prop.put("correlation_id", correlationId);
amqpMessage.bodyAsText = json;
amqpMessage.properties = prop;
System.log("Reply message : " + json);
System.log("CorrelationId: " + correlationId);
System.log("Sending AMQP message to exchange " + replyToExchange + "
with routing key " + replyTo);
broker.send(replyToExchange , replyTo , amqpMessage);
}
As Burke mentioned this requires to have the latest AMQP plug-in posted on communities.
You may also want to check my service builder package.
Christophe.
I haven't messed around with custom headers for AMQP but am wondering if you have tried the updated AMQP plug-in posted here: http://communities.vmware.com/docs/DOC-21770 -- I know that Christophe requires that for his Service extensions workflows so perhaps it is also what you need...
Here is a code sample
var msg = broker.retrieveMessage(messageTrigger);
if (msg != null) {
body = msg.bodyAsText;
properties = msg.properties;
headers = msg.headers;
replyToExchange = headers.get("replyToExchange");
var correlationId = properties.get("correlation_id");
var replyTo = properties.get("reply_to");
// Convert the JSON script to a javascript object
var messageBodyObject = eval(body);
var httpMessage = messageBodyObject[0];
//Modify the request and body property
httpMessage.request = false;
httpMessage.body = "SGVsbG8gQVBJIQ=="; // Sending "Hello API"
httpMessage.statusCode = 200;
// Converting javascript object back to JSON
var json =
System.getModule("com.vmware.web.webview").objectToJson(httpMessage);
var amqpMessage = new AMQPMessage();
var prop = new Properties();
prop.put("correlation_id", correlationId);
amqpMessage.bodyAsText = json;
amqpMessage.properties = prop;
System.log("Reply message : " + json);
System.log("CorrelationId: " + correlationId);
System.log("Sending AMQP message to exchange " + replyToExchange + "
with routing key " + replyTo);
broker.send(replyToExchange , replyTo , amqpMessage);
}
As Burke mentioned this requires to have the latest AMQP plug-in posted on communities.
You may also want to check my service builder package.
Christophe.
Hi,
A big thanks to the two of you !!!
My plug-in wasn't up to date, that's why my headers were not set !!
And Thanks for the script sample which help me a lot !!
Have you got more information of the encodage of the body : ??
httpMessage.body = "SGVsbG8gQVBJIQ=="; // Sending "Hello API"
It is base64. The linked package has encode / decode actions for it.
Great !! Thanks for your help !!
Le 22 févr. 2013 à 16:40, "Christophe Decanini" <communities-emailer@vmware.com<mailto:communities-emailer@vmware.com>> a écrit :
VMware Communities<http://communities.vmware.com/index.jspa>
Can't figure out how to set headers on amqp message
reply from Christophe Decanini<http://communities.vmware.com/people/cdecanini_> in Orchestrator - View the full discussion<http://communities.vmware.com/message/2199858#2199858