Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pjmuley
Created July 6, 2017 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjmuley/c1d15342ad7993758cde1ec555190174 to your computer and use it in GitHub Desktop.
Save pjmuley/c1d15342ad7993758cde1ec555190174 to your computer and use it in GitHub Desktop.
String queueName="myQueue";
String queueMessage="This is my test message";
String brokerURI="https://mq-us-west-2.anypoint.mulesoft.com/api/v1/organizations/";
brokerURI = brokerURI + orgId +"/environments/"+ envId +"/destinations/"+ queueName+"/messages";
// Post message to existing queue using API
String messageId=UUID.randomUUID().toString();
String postURI=brokerURI+"/"+messageId;
System.out.println(postURI);
// Message acknowledgement, effectively deleting message from the queue
JSONArray jsonArrayAck= (JSONArray) jsonParser.parse(outputGet); // Parse json output from retrieve message earlier to get lock id
JSONObject structureAck =(JSONObject) ((JSONObject)jsonArrayAck.get(0)).get("headers");
String lockId= (String)structureAck.get("lockId");
WebResource webResourceAck = client.resource(postURI);
String inputAck="{ \"lockId\": \""+lockId+"\" }";
ClientResponse responseAck=webResourceAck.header("Authorization"," bearer" + access_token)
.type("application/json")
.accept("application/json")
.delete(ClientResponse.class, inputAck);
String outputAck = responseAck.getEntity(String.class);
System.out.println("Ack Message: \n" + outputAck);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment