Anypoint MQ access using POSTMAN

Mulesoft's Cloud Based message offering Anypoint MQ provides you APIs which enable REST based access to send and receive messages, administer queues and message exchanges, and analyze results. This blog goes over the usage of these API's when running POSTMAN on Windows. Details around usage with CURL are already available on the Mulesoft Website.
With the Client ID and Client Secret handy, do a POST to the following endpoint - make sure you are passing the following parameters as x-www-form-urlencoded format to the endpoint
https://mq-us-east-1.anypoint.mulesoft.com/api/v1/authorize
client_id - this the client ID for your client app
client_secret - this the client secret for your client app
client_id - this the client ID for your destination
grant_type - client_credentials
Your Content-Type will be application/x-www-form-urlencoded ( surprise, surprise :)
If everything above is correct, you will get back a JSON response similar to the following
{
"access_token": "<token>", "simple_client": { "envId": "<env_ID>", "orgId": "<org-ID>" }, "token_type": "bearer" }
Your now ready to publish and receive messages. To start, construct an endpoint similar to the following

https://mq-us-east-1.anypoint.mulesoft.com/api/v1/organizations/<org_id>/environments/<env_id>/destinations/MyDemoQueue/messages/552

The number '552' above represents the Id of the message

Add the following headers

Content-Type - application/json
Authorization - bearer <bearer>
Cache-Control - no-cache
Postman-Token - <bearer>

Choose 'PUT' and the following payload

{
  "properties": {
    "userDefinedHeader": "User defined stuff",
    "anotherUserDefinedHeader": "Random stuff"
  },

  "body": "This is a message payload"

}

Verify the message made its way to the queue from the Anypoint MQ console


Use the following to GET a message off the queue




https://mq-us-east-1.anypoint.mulesoft.com/api/v1/organizations/<org_id>/environments/<env_id>/destinations/MyDemoQueue/messages?poolingTime=10000&batchSize=1&lockTtl=10000-us-east-1.anypoint.mulesoft.com/api/v1/organizations/<org_id>/environments/<env_id>/destinations/MyDemoQueue/messages?poolingTime=10000&batchSize=1&lockTtl=10000

You should get a response similar to the following

[
  {
    "properties": {
      "anotherUserDefinedHeader": "Random stuff",
      "userDefinedHeader": "User defined stuff"
    },
    "headers": {
      "messageId": "552",
      "lockId": "AQEB7XNaLwMcjLPgsGLfVdtAJi4EFC5n1i8kVJ/Jft1rGTQoZwsgF2MtUeYsO/bm9T8Byhn8VlnufZJKNgX4ztrbzd4JS0ATLXXqt3LHTpg2Dtxv3ovLBm7Cj8tjrfmqFWRfo8v3LlQrdpKYWTigIUqMiEWX1AUmkAzp9BoSxYm9nNMjjxgroaj+Kh9JsWNWDI29sWd1d8S3iThg8b70GFE+Zn0ZMyJWBuPBU8gMVJ2TQW2muwdWI/j4q9OePLL1Ma6STK5bc19mmnWLYY77ELqSlr61jJj7tQALLJaHVTD8mIQzxk+bmVTBPw3wuqiHk10GZTPtar5KM99sbAyI/CrYdzY8KB7W77zeAVsZC0GDkpuV1URcvjg+XVHl30gnFZhRZdluO4nMKOHET19DF7K2kI9LIO6Kj75C9LjWaknQpKw=",
      "created": "Thu, 6 Apr 2017 17:23:57 GMT",
      "deliveryCount": "2"
    },
    "body": "This is a message payload"
  }
]




Comments

  1. From where will we get the message id?

    ReplyDelete
  2. Your GET is messed up. You listed the full URL twice, and you misspelled "polling".

    ReplyDelete

Post a Comment

Popular posts from this blog

Legacy to API Led Connectivity with Mulesoft

Publish – Subscribe Messaging with Anypoint MQ