VMware Cloud Community
clabman
Contributor
Contributor
Jump to solution

Can't figure out how to set headers on amqp message

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

var rep = new AMQPMessage();
rep.bodyAsText = "My reply";
rep.headers=heads;
rep.properties=props;
broker.send("vcd.replyExchange","routingkey",rep);
System.log(rexchange + rkey + rep);

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 ?

0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

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.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

0 Kudos
5 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

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...

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
cdecanini_
VMware Employee
VMware Employee
Jump to solution

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.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
clabman
Contributor
Contributor
Jump to solution

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"

0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

It is base64. The linked package has encode / decode actions for it.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
clabman
Contributor
Contributor
Jump to solution

Great !! Thanks for your help !! Smiley Happy

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

0 Kudos